I have a method which gets a row from 1 table puts it into a clonetable.
In the clone table I change the values in 2 of the columns, then I use import row to put them back into the original table as a new row.
But when I try to save/update it I get the folowing errormessage:
My Code looks like this:
I use a savebutton who calls a statement like this:
But I do not understand why I get the errormessage.
I do have a table called prosess_18, who uses OrdreID as a foreign key
But I have not put any data into that table or any of the other tables yet.
But Prosess_18 is the only one I get an error from.
And I haven't changed anything in that table which should cause any problems.
Anyone have a clue where the problem might be?
In the clone table I change the values in 2 of the columns, then I use import row to put them back into the original table as a new row.
But when I try to save/update it I get the folowing errormessage:

My Code looks like this:
VB.NET:
Dim dtbl As New DataTable
Dim dt As New DataTable
dtbl = Kalkyle1DataSet.Tables("Ordre")
dt = dtbl.Clone
Dim copyRows1 As DataRow
Dim copyRows() As DataRow = _
Kalkyle1DataSet.Ordre.Select("OrdreID = 1")
Dim newOrdreRow As DataRow = Kalkyle1DataSet.Tables("Ordre").NewRow()
For Each copyRows1 In copyRows
dt.Rows.Clear()
Next
For Each copyRows1 In copyRows
dt.ImportRow(copyRows1)
Next
DataGridView1.DataSource = dt
MsgBox("Forsøker å Endre data")
'*********************************************************************
Dim conn = New SqlClient.SqlConnection
conn = New SqlConnection(Form1.DS2)
Dim myScalarQuery As String
Dim ID As Integer
Dim MaxID As Integer
Dim KundeID As Integer
conn.Open()
myScalarQuery = " Select Max(OrdreID) As ID From Ordre"
Dim myCommand As New SqlCommand(myScalarQuery, conn)
ID = myCommand.ExecuteScalar()
conn.Close()
MaxID = ID + 1
KundeID = CInt(KundeIDTextBox.Text)
Dim n As Integer = 0
For Each copyRows1 In copyRows
dt.Rows(n)("OrdreID") = MaxID
dt.Rows(n)("KundeID") = KundeID
n = n + 1
Next
DataGridView1.DataSource = dt
MsgBox("Forsøker å legge inn data i ordretabell")
Dim copyRow1 As DataRow
Dim copyRow() As DataRow = _
dt.Select("OrdreID = 3")
For Each copyRow1 In copyRow
Kalkyle1DataSet.Tables("Ordre").ImportRow(copyRow1)
Next
I use a savebutton who calls a statement like this:
VB.NET:
Dim ordreUpdates() As DataRow = Me.Kalkyle1DataSet.Ordre.Select("", "", DataViewRowState.Added Or DataViewRowState.ModifiedCurrent)
and calls with
Me.OrdreTableAdapter.Update(ordreUpdates)
But I do not understand why I get the errormessage.
I do have a table called prosess_18, who uses OrdreID as a foreign key
But I have not put any data into that table or any of the other tables yet.
But Prosess_18 is the only one I get an error from.
And I haven't changed anything in that table which should cause any problems.
Anyone have a clue where the problem might be?