P
phonl
VB.NET 2005 and ADO2.NET
After years of VB6 and ADO coding, I'm checking out ADO2.NET.
I spent several hours trying to figure out why the line:
objDataAdapter.Update(objDataSet, "myTable")
caused this error:
Update requires a valid UpdateCommand when passed DataRow collection with
modified rows.
In this code:
objDataSet.Tables("myTable").Rows(1).EndEdit()
If objDataSet.HasChanges Then
objDataAdapter.Update(objDataSet, "myTable") <--error here
End If
After much Google, I found that adding this line solved the problem:
Dim cb As New OleDb.OleDbCommandBuilder(objDataAdapter)
So the working code is:
Dim cb As New OleDb.OleDbCommandBuilder(objDataAdapter)
objDataSet.Tables("myTable").Rows(1).EndEdit()
If objDataSet.HasChanges Then
objDataAdapter.Update(objDataSet, "myTable")
End If
What's going on here? What is "cb" doing to the DataAdapter?
After years of VB6 and ADO coding, I'm checking out ADO2.NET.
I spent several hours trying to figure out why the line:
objDataAdapter.Update(objDataSet, "myTable")
caused this error:
Update requires a valid UpdateCommand when passed DataRow collection with
modified rows.
In this code:
objDataSet.Tables("myTable").Rows(1).EndEdit()
If objDataSet.HasChanges Then
objDataAdapter.Update(objDataSet, "myTable") <--error here
End If
After much Google, I found that adding this line solved the problem:
Dim cb As New OleDb.OleDbCommandBuilder(objDataAdapter)
So the working code is:
Dim cb As New OleDb.OleDbCommandBuilder(objDataAdapter)
objDataSet.Tables("myTable").Rows(1).EndEdit()
If objDataSet.HasChanges Then
objDataAdapter.Update(objDataSet, "myTable")
End If
What's going on here? What is "cb" doing to the DataAdapter?