Connie Jerdet-Skehan
asked on
System.Data.ConstraintException error visual basic
I am a newbie
Using visual studio and visual basic form
I am trying to copy a selected row or rows from Datagridview and paste it to the same datagridview.
I can do this with no problem when the table DOES NOT have a primary key.
I now have a table with a primary key and get an System.Data.ConstraintExce ption error "Column "id" is constrained to be unique. Value "1" is already present.
I assume I have to add 1 to the last record number but don't know how to do this or where to put in my code.
here is my code with help courtesy of Chinmay Patel
Dim table = MyDataSet.MyTable
For index = 0 To DataGridView1.SelectedRows .Count - 1
Dim row As DataRow
row = CType(DataGridView1.Select edRows(ind ex).DataBo undItem, DataRowView).Row
Dim newRow As DataRow
newRow = table.NewRow
newRow.ItemArray = row.ItemArray
table.Rows.Add(newRow)
Next
I appreciate all help. I have spent days trying to figure out how to overcome this. Explanation and code fix would be highly appreciated.
Using visual studio and visual basic form
I am trying to copy a selected row or rows from Datagridview and paste it to the same datagridview.
I can do this with no problem when the table DOES NOT have a primary key.
I now have a table with a primary key and get an System.Data.ConstraintExce
I assume I have to add 1 to the last record number but don't know how to do this or where to put in my code.
here is my code with help courtesy of Chinmay Patel
Dim table = MyDataSet.MyTable
For index = 0 To DataGridView1.SelectedRows
Dim row As DataRow
row = CType(DataGridView1.Select
Dim newRow As DataRow
newRow = table.NewRow
newRow.ItemArray = row.ItemArray
table.Rows.Add(newRow)
Next
I appreciate all help. I have spent days trying to figure out how to overcome this. Explanation and code fix would be highly appreciated.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER