Results 1 to 4 of 4

Thread: problem in updating multiple tables in dataset...

  1. #1

    Thread Starter
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416

    problem in updating multiple tables in dataset...

    halu. im a newbie
    i used datagrid to place multiple tables w/ corresponding data from the database
    i could update the first table and it saves into the database what i've change but when i'm going to update the second table it gives me an error: missing the datacolumn "code" in the Datatable 'gallons' for the SourceColumn 'code'
    i dont know how to figure it out.

    Code:
    dim cn as new sqlconnection("......")
    dim cm as new sqlcommand()
    Private ds as new dataset()
    dim da as new Sqldataadapter()
    dim cmdtext as string
    
    'form load
    
    cn.open
    cm.connection=cn
    cm.commandtype = commandtype.storedprocedure
    cmdtext = "select * from customertable ; select * from gallons"
    da.selectcommand = new sqlcommand(cmdtext, cn)
    da.tablemappings="Table","Customer"
    da.tablemappings="Table1","Gallons"
    da.fill(ds)
    datagrid1.datasource = ds
    
    'to save the changes
    
    if ds.haschanges then
        dim cb as Sqlcommandbuilder
        da.selectcommand = new sqlcommand(cmdtext,cn)
        cb = new sqlcommandbuilder(da)
        da.Update(ds,"Customer")
        da.Update(ds,"Gallons")
    end if
    tanx in advance....

  2. #2
    Hyperactive Member
    Join Date
    May 2002
    Location
    Wisconsin, USA
    Posts
    279
    I'm having the same problem, except mine says: Missing the DataColumn 'Date' in the DataTable 'FeeChargeAttendance' for the SourceColumn 'Date' I don't even have a column named 'Date' in any of the tables I'm working with.

    Code:
    An unhandled exception of type 'System.InvalidOperationException' occurred in system.data.dll
    
    Additional information: Missing the DataColumn 'Date' in the DataTable 'FeeChargeAttendance' for the SourceColumn 'Date'.
    I think this must be some kind of bug in the SQLClient namespace.

  3. #3

    Thread Starter
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416
    hello..sorry for leaving this thread.

    the proper way to update multiple tables is to use different adapters on it.

    and if updating a master-detail table is to use relation object.

  4. #4
    Hyperactive Member
    Join Date
    May 2002
    Location
    Wisconsin, USA
    Posts
    279
    I figured this one out before you posted a reply. Here is a more detailed description to hopefully better help others out:

    One way to fill a DataSet with multiple tables is to send the database multiple requests. Another way to do this is to use multiple SELECT statements in a single request.

    There are a couple of problems with doing it this way:
    1) The DataTables don't have the same name as the tables in the database, you have to set them yourself
    2) You can't update/save the tables to the database; to do that you must use a seperate DataAdapter for each table.

    VB Code:
    1. Dim myAdapter as SqlDataAdapter = new SqlDataAdapter(“SELECT * FROM Customers; SELECT * FROM Orders“, connection)
    2.  
    3. myAdapter.Fill(dsTables)
    4. dsTables.Tables(0).TableName = “Customers“)
    5. dsTables.Tables(1).TableName = “Orders“)

    It would be so much easier if they made it so you can use the same DataAdapter to update all the tables you load into the DataSet with the DataAdapter.

    If you do try to update all the tables with the same DataAdapter, then you will get an error like the one below (this error really frustrated me for a couple hours):

    Code:
    An unhandled exception of type 'System.InvalidOperationException' occurred in system.data.dll
    
    Additional information: Missing the DataColumn 'Date' in the DataTable 'FeeChargeAttendance' for the SourceColumn 'Date'.

Posting Permissions

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



Click Here to Expand Forum to Full Width