J
JFB
Hi,
I have two tables with one relation in a dataAdapter, I pass all the records
to a couple datagrids.
After add, update and delete records.... I'm trying to update the
dataAdapter with the all changes.
I read in my book that I need to do it in particular order:
1.Submit New rows for both tables.
2.Submit Modified rows for both tables.
3.Submit Deletes rows for both tables.
I have a Update bottom in my vb.net form with the above code.
Can someome help me to fix the error after I try to do an update "Update
requieres a
Valid Update command when passed data row ...."
Also if I delete something it said... "update requieres a Valid Delete
Command...."
Do I need to create an add, update and delete command?
Do you have an example?
Tks in advance
JFB
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnUpdate.Click
Dim tblPersons As DataTable = hSet.Tables("Persons")
Dim tblNewPersons As New DataTable
Dim tblHouses As DataTable = hSet.Tables("Houses")
Dim tblNewHouses As New DataTable
Dim daPersons As New SqlDataAdapter
Dim intOrdersModified As Integer
Try
'Update changes for New Records
If hSet.HasChanges(DataRowState.Added) Then
tblNewPersons = tblPersons.GetChanges(DataRowState.Added)
intOrdersModified = hAdapter.Update(tblNewPersons)
tblNewHouses = tblHouses.GetChanges(DataRowState.Added)
hAdapter.Update(tblNewHouses)
End If
'Update changes for modified Records
If hSet.HasChanges(DataRowState.Modified) Then
tblNewPersons = tblPersons.GetChanges(DataRowState.Modified)
intOrdersModified = hAdapter.Update(tblNewPersons)
tblNewHouses = tblHouses.GetChanges(DataRowState.Modified)
hAdapter.Update(tblNewHouses)
End If
'Update changes for Records deleted
If hSet.HasChanges(DataRowState.Deleted) Then
tblNewPersons = tblPersons.GetChanges(DataRowState.Deleted)
intOrdersModified = hAdapter.Update(tblNewPersons)
tblNewHouses = tblHouses.GetChanges(DataRowState.Deleted)
hAdapter.Update(tblNewHouses)
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
I have two tables with one relation in a dataAdapter, I pass all the records
to a couple datagrids.
After add, update and delete records.... I'm trying to update the
dataAdapter with the all changes.
I read in my book that I need to do it in particular order:
1.Submit New rows for both tables.
2.Submit Modified rows for both tables.
3.Submit Deletes rows for both tables.
I have a Update bottom in my vb.net form with the above code.
Can someome help me to fix the error after I try to do an update "Update
requieres a
Valid Update command when passed data row ...."
Also if I delete something it said... "update requieres a Valid Delete
Command...."
Do I need to create an add, update and delete command?
Do you have an example?
Tks in advance
JFB
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnUpdate.Click
Dim tblPersons As DataTable = hSet.Tables("Persons")
Dim tblNewPersons As New DataTable
Dim tblHouses As DataTable = hSet.Tables("Houses")
Dim tblNewHouses As New DataTable
Dim daPersons As New SqlDataAdapter
Dim intOrdersModified As Integer
Try
'Update changes for New Records
If hSet.HasChanges(DataRowState.Added) Then
tblNewPersons = tblPersons.GetChanges(DataRowState.Added)
intOrdersModified = hAdapter.Update(tblNewPersons)
tblNewHouses = tblHouses.GetChanges(DataRowState.Added)
hAdapter.Update(tblNewHouses)
End If
'Update changes for modified Records
If hSet.HasChanges(DataRowState.Modified) Then
tblNewPersons = tblPersons.GetChanges(DataRowState.Modified)
intOrdersModified = hAdapter.Update(tblNewPersons)
tblNewHouses = tblHouses.GetChanges(DataRowState.Modified)
hAdapter.Update(tblNewHouses)
End If
'Update changes for Records deleted
If hSet.HasChanges(DataRowState.Deleted) Then
tblNewPersons = tblPersons.GetChanges(DataRowState.Deleted)
intOrdersModified = hAdapter.Update(tblNewPersons)
tblNewHouses = tblHouses.GetChanges(DataRowState.Deleted)
hAdapter.Update(tblNewHouses)
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub