DataAdapter.Update question

IfYouSaySo

Well-known member
Joined
Jan 4, 2006
Messages
102
Location
Hermosa Beach, CA
Programming Experience
3-5
Hi,

I'm just trying to figure out why the following bit of code doesn't work. It executes normally, there are some rows in the dataset just before I da.Update, but nothing ends up in the database. Probably something related to my understanding of SqlCommandBuilder...? BTW, there currently is nothing in the db, so this is actually just some inserts, but I want it to work as either inserts or updates.

Also...related quesiton. This (eventually) will work for one table. But what if there are more tables in the dataset? How do I get those tables to update as well? (Another SqlCommandBuilder question I guess..)
VB.NET:
    Sub Main()
        Dim cxn As New SqlConnection(My.Settings.ConnectionString)
        cxn.Open()

        Dim da As New SqlDataAdapter(My.Settings.CustomersSelectStatement, cxn)
        Dim cb As New SqlCommandBuilder(da)
        Dim ds As New MyDataset

        ' grab existing data
        da.Fill(ds)

        ' now update with data from file
        Dim dsf As New MyDataset
        dsf.ReadXml(My.Settings.InputFile)
        ds.Merge(dsf, False)

        ' write back to db
        da.Update(ds)
        ds.AcceptChanges()
        cxn.Close()
    End Sub
 
So the problem was that Fill and Update wanted me to use the version where I give the table name; and the table name needed to match exactly the table name in the xml schema. I guess it makes sense, after I figured it out!
 
Back
Top