none
Using Merge for two DataSets RRS feed

  • Question

  • I was wondering why this block of code:

    Code Snippet

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim conNorthwind1 As OleDb.OleDbConnection
            Dim conNorthwind2 As OleDb.OleDbConnection

            Dim daCustomers1 As Data.OleDb.OleDbDataAdapter
            Dim dsCustomers1 As Data.DataSet

            Dim daCustomers2 As Data.OleDb.OleDbDataAdapter
            Dim dsCustomers2 As Data.DataSet

            Dim builder1 As New Data.OleDb.OleDbConnectionStringBuilder
            Dim builder2 As New Data.OleDb.OleDbConnectionStringBuilder

            builder1.Provider = "Microsoft.Jet.OLEDB.4.0"
            builder1.DataSource = My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\Northwind.mdb"
            builder2.Provider = "Microsoft.Jet.OLEDB.4.0"
            builder2.DataSource = My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\Northwind2.mdb"

            conNorthwind1 = New OleDb.OleDbConnection
            conNorthwind1.ConnectionString = builder1.ConnectionString
            conNorthwind1.Open()

            conNorthwind2 = New OleDb.OleDbConnection
            conNorthwind2.ConnectionString = builder2.ConnectionString
            conNorthwind2.Open()

            daCustomers1 = New Data.OleDb.OleDbDataAdapter("SELECT * FROM Customers", conNorthwind1)
            dsCustomers1 = New Data.DataSet

            daCustomers1.Fill(dsCustomers1, "Customers")

            daCustomers2 = New Data.OleDb.OleDbDataAdapter("SELECT * FROM Customers", conNorthwind2)
            dsCustomers2 = New Data.DataSet

            daCustomers2.Fill(dsCustomers2, "Customers")

            dsCustomers1.Merge(dsCustomers2)
            daCustomers1.Update(dsCustomers1)

        End Sub


    produces the following error on the Update line:

    System.InvalidOperationException was unhandled
      Message="Update unable to find TableMapping['Table'] or DataTable 'Table'."
      Source="System.Data"

    What else has to be done when using a merge?

    Thanks,
    Mark Oberg
    Wednesday, February 13, 2008 4:08 PM