Bascily I am trying to append a table to another table in a completely different database. This code here gives me an error. Any ideas on how to fix it?
------
System.ArgumentException: This row already belongs to another table. at System.Data.DataTable.InsertRow(DataRow row, Int32 proposedID, Int32 pos) at System.Data.DataRowCollection.Add(DataRow row) at internalweb2.admin_quickpak.CatalogMaster(DataSet myds)
Code:
Private Sub CatalogMaster(ByVal myds As System.Data.DataSet)
Try
Dim Connect As New SqlClient.SqlConnection
Dim Adapter As New SqlClient.SqlDataAdapter
Dim Ds As New DataSet
Dim i
Dim ConnectString, SelectStatement As String
SelectStatement = "Select * from catalogmaster WHERE CRID = -1"
ConnectString = ConfigurationSettings.AppSettings("InternalWeb")
Connect.ConnectionString = ConnectString
Adapter.SelectCommand = _
New SqlClient.SqlCommand(SelectStatement, Connect)
Adapter.SelectCommand.Connection.Open()
Adapter.Fill(Ds, "catalogmaster")
For i = 0 To myds.Tables(0).Rows.Count - 1
Ds.Tables("catalogmaster").Rows.Add(myds.Tables(0).Rows(i))
Next
Dim buildCommands As SqlClient.SqlCommandBuilder = New SqlClient.SqlCommandBuilder(Adapter)
Adapter.Update(Ds, "catalogmaster")
Connect.Close()
Catch exc As Exception
label1.Text = exc.ToString
End Try
End Sub
------