Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

add one dataset to another dataset

Status
Not open for further replies.

jondel81

Technical User
Jul 27, 2003
71
US
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

------
 
try this

Code:
 Ds.Tables("catalogmaster").Rows.Add(myds.Tables(0).Rows(i).copy)

or

Code:
 Ds.Tables("catalogmaster").Rows.Add(myds.Tables(0).Rows(i).clone)

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top