I want to have a dataset consisting of 3 tables. I originally did it with a single SELECT statement:
But found (from experience and other sites) that the update command won't work for tables added like this. Instead, I needed to change my code to:Code:myDataAdapter = New SQLDataAdapter("SELECT * FROM Table1; SELECT * FROM Table2; SELECT * FROM Table3", myConnection)
and issue 3 separate FILL statements to properly fill the dataset with the 3 tables.Code:myDataAdapter1 = New SqlDataAdapter("SELECT * FROM Table1", myCon) myDataAdapter2 = New SqlDataAdapter("SELECT * FROM Table2", myCon) myDataAdapter3 = New SqlDataAdapter("SELECT * FROM Table3", myCon)
I also found that I need to use the command builder:
to get the update to work properly.Code:myCommandBuilder = New SqlCommandBuilder(myDataAdapter1) myCommandBuilder = New SqlCommandBuilder(myDataAdapter2) myCommandBuilder = New SqlCommandBuilder(myDataAdapter3)
I use the following code, for example, to update Table 3:
So my question is, if I have to deal with 3 separate data adapters, why not just create 3 separate tables? What's the benefit of having all 3 tables in a single dataset of the separate adapters need to be used anyway?Code:myDataAdapter3.Update(myDS, "Table3")
Greg


Reply With Quote