Results 1 to 12 of 12

Thread: Dataset fill

  1. #1
    michaelw is offline VB.NET Forum Newbie
    .NET Framework
    Join Date
    Jun 2005
    Posts
    25
    Reputation
    99

    Wink Dataset fill

    Hi i am trying to connect to a database using an sql adapter, when i fill the dataset i get an error in the output window it says

    "Unhandled Exception: System.Data.SqlClient.SqlException: Cannot open database requested in login 'testbooking'. Login fails."

    But the server does exsit and so does the database

    i can connect using an oledb adapter but i really dont want to have to

    any help would be great

  2. #2
    ManicCW's Avatar
    ManicCW is offline VB.NET Forum Miyagee
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Jul 2005
    Location
    Mostar
    Posts
    428
    Reputation
    106
    here is what connection should look like:

    SQL Autentication:

    data source=YOURSERVERNAME;persist security info=False;initial catalog=YOURDATABASENAME;user id=sa;password=YOURPASS;

    Windows Autentication:

    data source=YOURSERVERNAME;persist security info=False;initial catalog=YOURDATABASENAME;integrated security=SSPI;

  3. #3
    TechGnome is offline VB.NET Forum Idol
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    May 2005
    Posts
    896
    Reputation
    216
    And is it a SQL Server? That's the only way the SQL Adapter is going to work. The fact that you can connect using the OLEDB Adapter leads me to suspect that it isn't a SQL Server, but something else./

    Tg

  4. #4
    michaelw is offline VB.NET Forum Newbie
    .NET Framework
    Join Date
    Jun 2005
    Posts
    25
    Reputation
    99

    Wink

    No it is SQL server it just giives me an error with the sql adapter method. I will try you way and keep you posted thanks

  5. #5
    michaelw is offline VB.NET Forum Newbie
    .NET Framework
    Join Date
    Jun 2005
    Posts
    25
    Reputation
    99

    Wink

    The connection you posted is the same as mine but it throughs the error message back???

  6. #6
    tarunkapoor is offline VB.NET Forum Newbie
    .NET Framework
    Join Date
    Apr 2005
    Posts
    17
    Reputation
    101
    can you post your connection string

  7. #7
    TechGnome is offline VB.NET Forum Idol
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    May 2005
    Posts
    896
    Reputation
    216
    Point of order your honor! It's a bad idea to use the sa user for connecting to the database, case DBA vs SA-User-With-No-Password of 1997. I move that the user be stricken from the access list.

    If you do post your connectionstring, post it EXACTLY as it is, but use **** for the password.... we don't need to see that.

    Tg

  8. #8
    nakracreative is offline VB.NET Forum Enthusiast
    .NET Framework
    Join Date
    Aug 2005
    Location
    India
    Posts
    72
    Reputation
    99

    connection with the database

    if your dataadapter contains no tables then dataset cannot be populated and it will show an error when you write the command

    sqlclient.sqldataadapter.fill(dataset(),<tablename >)

    so check if your dataadapter is not linked with any table of your database

  9. #9
    michaelw is offline VB.NET Forum Newbie
    .NET Framework
    Join Date
    Jun 2005
    Posts
    25
    Reputation
    99

    Unhappy

    Hi thanks for your help with this, i have moved on and am now using the oledb adapter but have come across anothe problem, i generate this through the wizard and when it has finsihed it tells me it can not create the update or delete commands.

    My project as it stands is this:

    I have an excel sheet with two coloums one called URN and one invoiecno, i import the data into a dataset > ds1, i then have a tables called jobs in sql server i create a dataset> ds2 with coulms urn and invoice number. i wish to update the sql server table coloum invoice number to the invoice number in the excel sheet where the urn are the same in ds1 & ds2

    any help would be great

  10. #10
    michaelw is offline VB.NET Forum Newbie
    .NET Framework
    Join Date
    Jun 2005
    Posts
    25
    Reputation
    99
    The erro message i get is:


    An unhandled exception of type 'System.InvalidOperationException' occurred in system.data.dll
    Additional information: Update requires a valid UpdateCommand when passed DataRow collection with modified rows.

    my code is

    PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    DataSet11.Clear()

    OleDbDataAdapter1.Fill(DataSet11)

    EndSub

    PrivateSub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

    OleDbDataAdapter1.Update(DataSet11)

    MessageBox.Show("Datbase Updated")

    EndSub


  11. #11
    nakracreative is offline VB.NET Forum Enthusiast
    .NET Framework
    Join Date
    Aug 2005
    Location
    India
    Posts
    72
    Reputation
    99
    u have used the following set of code:

    PrivateSub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

    OleDbDataAdapter1.Update(DataSet11)

    MessageBox.Show("Datbase Updated")

    EndSub


    this is the right one:-

    whenever u are updating dataadapter in this manner then u must first instantiate the commandbuilder object.

    dim objcommandbuilder as new sqlclient.sqlcommandbuilder(objdataadapter)

    oledbdatadapter1.update(dataset11,<tablename>)

    u have to provide the tablename option.


  12. #12
    michaelw is offline VB.NET Forum Newbie
    .NET Framework
    Join Date
    Jun 2005
    Posts
    25
    Reputation
    99
    ok manged to sort previous post out have one more snag?


    on the line

    objdataview.Table(0).ow(inum).item("URN") = "TEST"

    it says it can not be indexed because it has no default value

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking