954,529 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

add datatable to sql table

I have a set of code that builds a table as the user enters information. This information may be changed more than once before it is considered complete. After the user is done, I want them to click a button, and have that information entered into the SQL database where it belongs. Right now, the code I am using gives the error:
"System.ArgumentException: This row already belongs to another table"

Is there a way to add a table to a table like this, or do I need to add each row to the SQL table as the user moves along.

Any help is much appreciated!

Try
            For Each row In Me.tblTraining
                Me.DataSet1.docContent.Rows.Add(row)
                Me.DocContentTableAdapter.Update(Me.DataSet1.docContent)
            Next
        Catch w As Exception
            MsgBox(w.ToString)
        End Try
bklynman01
Junior Poster in Training
94 posts since Oct 2010
Reputation Points: 12
Solved Threads: 6
 

First let me know Where u Fill The Value in parameter row and does it execute one time then gives error

manoj_582033
Light Poster
39 posts since Nov 2008
Reputation Points: 10
Solved Threads: 2
 

Thank you very much for the quick response. I actually solved the problem after moving on to the next task.

The reason it would not add the row is because the KEY ID row in the new table matched one of the rows in the SQL table that already existed. I created a new SQL function that would get the highest identifying row number, added 1 (+1), and began inserting rows there. Works like a charm now.

Thanks anyway!

bklynman01
Junior Poster in Training
94 posts since Oct 2010
Reputation Points: 12
Solved Threads: 6
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: