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
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