Click to See Complete Forum and Search --> : Updating/Inserting into DataSource from a DataSet with multiple Tables


Nasty2
January 11th, 2006, 11:07 AM
Hey all,

I got a DataSet with 8 DataTables inside..... Filled the DataSet with the following code:
Dim conn As New MySqlConnection
Dim ECNDA As MySqlDataAdapter
Dim tablenames() As String = {"BopOptions", "BomRouting", "ProgramChanges", "StockedParts", "JigTools", "Status", "ChangeCategories", "Originators"}

For i As Integer = 0 To tablenames.GetUpperBound(0)
Dim sql As String = "Select " & tablenames(i) & ".* From " & tablenames(i)

If ConfigurationSettings.AppSettings("CompLocation") = "1" Then
conn.ConnectionString = connStringLocal
End If
If ConfigurationSettings.AppSettings("CompLocation") = "2" Then
conn.ConnectionString = connStringForeign
End If

ECNDA = New MySqlDataAdapter(sql, conn)
Dim myTable As New DataTable(tablenames(i))
ECNDA.Fill(myTable)
COMBOSDS.Tables.Add(myTable)
conn.Close()
Next
It seems to work fine....... this is the right way to do things, right?

How can I insert the changes I have done to one particular Table into the DataBase?
I searched around for an answer, but only got examples using one table in the DataSet.

Thanks

jhammer
January 12th, 2006, 01:53 AM
check the SQLDataAdapter.Update method. You pass a Dataset and a Table name.

Nasty2
January 12th, 2006, 02:19 AM
I just can't get it.

I am declaring a MySqlDataAdapter and a DataSet as Global so I can use them for various forms.
I am populating my DataSet with 8 Tables with the following code:
Dim conn As New MySqlConnection

Dim tablenames() As String = {"BopOptions", "BomRouting", "ProgramChanges", "StockedParts", "JigTools", "Status", "ChangeCategories", "Originators"}
For i As Integer = 0 To tablenames.GetUpperBound(0)
Dim sql As String = "Select " & tablenames(i) & ".* From " & tablenames(i)

If ConfigurationSettings.AppSettings("CompLocation") = "1" Then
conn.ConnectionString = connStringLocal
End If
If ConfigurationSettings.AppSettings("CompLocation") = "2" Then
conn.ConnectionString = connStringForeign
End If

COMBOSDA = New MySqlDataAdapter
COMBOSDA.SelectCommand = New MySqlCommand(sql, conn)
Dim custCB As MySqlCommandBuilder = New MySqlCommandBuilder(COMBOSDA)
Dim myTable As New System.Data.DataTable(tablenames(i))
conn.Open()
COMBOSDA.Fill(myTable)
COMBOSDS.Tables.Add(myTable)
conn.Close()
Next

I then make all the changes that I need to do to the DataSet.
I tried using the Update method
COMBOSDA.Update(COMBOSDS.Tables("BomRouting"))
....but nothing is written to the Database and no error is shown

Is it because I am closing the connection in the first code snippet?