IfYouSaySo
Well-known member
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..)
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