|
-
January 11th, 2006, 12:07 PM
#1
Updating/Inserting into DataSource from a DataSet with multiple Tables
Hey all,
I got a DataSet with 8 DataTables inside..... Filled the DataSet with the following code:
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
-
January 12th, 2006, 02:53 AM
#2
Re: Updating/Inserting into DataSource from a DataSet with multiple Tables
check the SQLDataAdapter.Update method. You pass a Dataset and a Table name.
-
January 12th, 2006, 03:19 AM
#3
Re: Updating/Inserting into DataSource from a DataSet with multiple Tables
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:
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
Code:
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?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|