J
john_j_whalen
I hope someone can help me with my error :
An unhandled exception of type 'System.Data.ConstraintException'
occurred in system.data.dll
Additional information: Failed to enable constraints. One or more rows
contain values violating non-null, unique, or foreign-key constraints.
I am able to create a 2 column table, add a primary key, add rows to
the table, then update the table all using LoadDataRow.
When I read an .XML file and attempt to do the same update I get the
error. Any insight into what I am missing would be greatly
appreciated.
CODE THAT WORKS
Dim dt As New DataTable, dc1 As New DataColumn, dc2 As New
DataColumn
dc1.ColumnName = "ONE"
dc1.DataType = System.Type.GetType("System.String")
dc2.ColumnName = "TWO"
dc2.DataType = System.Type.GetType("System.String")
dt.Columns.Add(dc1)
dt.Columns.Add(dc2)
Dim dcPK(0) As DataColumn
dcPK(0) = dt.Columns(0)
dt.PrimaryKey = dcPK
Dim mydata(1) As Object
mydata(0) = "A"
mydata(1) = "B"
dt.LoadDataRow(mydata, True)
mydata(0) = "C"
mydata(1) = "D"
dt.LoadDataRow(mydata, True)
Dim drow As DataRow
For Each drow In dt.Rows
MsgBox(drow.ItemArray(0))
MsgBox(drow.ItemArray(1))
Next drow
mydata(0) = "A"
mydata(1) = "F"
dt.LoadDataRow(mydata, True)
For Each drow In dt.Rows
MsgBox(drow.ItemArray(0))
MsgBox(drow.ItemArray(1))
Next drow
CODE THAT FAILS
Dim ds As New DataSet
ds.ReadXml("C:\TEST.xml")
'ADD A PK
Dim dcPK(0) As DataColumn
dcPK(0) = ds.Tables(0).Columns(0)
ds.Tables(0).PrimaryKey = dcPK
'CHANGE DATA
Dim ar(1) As Object
ar(0) = "44" 'ORIG VALUE IS INTEGER 44
ar(1) = "Updated" 'ORIG VALUE IS "OrigValue"
ds.Tables(0).BeginLoadData()
ds.Tables(0).LoadDataRow(ar, True)
ds.Tables(0).EndLoadData() 'ERROR HERE
An unhandled exception of type 'System.Data.ConstraintException'
occurred in system.data.dll
Additional information: Failed to enable constraints. One or more rows
contain values violating non-null, unique, or foreign-key constraints.
I am able to create a 2 column table, add a primary key, add rows to
the table, then update the table all using LoadDataRow.
When I read an .XML file and attempt to do the same update I get the
error. Any insight into what I am missing would be greatly
appreciated.
CODE THAT WORKS
Dim dt As New DataTable, dc1 As New DataColumn, dc2 As New
DataColumn
dc1.ColumnName = "ONE"
dc1.DataType = System.Type.GetType("System.String")
dc2.ColumnName = "TWO"
dc2.DataType = System.Type.GetType("System.String")
dt.Columns.Add(dc1)
dt.Columns.Add(dc2)
Dim dcPK(0) As DataColumn
dcPK(0) = dt.Columns(0)
dt.PrimaryKey = dcPK
Dim mydata(1) As Object
mydata(0) = "A"
mydata(1) = "B"
dt.LoadDataRow(mydata, True)
mydata(0) = "C"
mydata(1) = "D"
dt.LoadDataRow(mydata, True)
Dim drow As DataRow
For Each drow In dt.Rows
MsgBox(drow.ItemArray(0))
MsgBox(drow.ItemArray(1))
Next drow
mydata(0) = "A"
mydata(1) = "F"
dt.LoadDataRow(mydata, True)
For Each drow In dt.Rows
MsgBox(drow.ItemArray(0))
MsgBox(drow.ItemArray(1))
Next drow
CODE THAT FAILS
Dim ds As New DataSet
ds.ReadXml("C:\TEST.xml")
'ADD A PK
Dim dcPK(0) As DataColumn
dcPK(0) = ds.Tables(0).Columns(0)
ds.Tables(0).PrimaryKey = dcPK
'CHANGE DATA
Dim ar(1) As Object
ar(0) = "44" 'ORIG VALUE IS INTEGER 44
ar(1) = "Updated" 'ORIG VALUE IS "OrigValue"
ds.Tables(0).BeginLoadData()
ds.Tables(0).LoadDataRow(ar, True)
ds.Tables(0).EndLoadData() 'ERROR HERE