Problem with update data from the dataset to the database


Can someone please help me to solve this problem? I am trying to update the data from the dataset to the database with the following code, but what I get back after run this program is an error like this "An unhandled exception of type 'System.InvalidOperationException' occurred in Additional information: Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information"

Here is my code:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

' Declare a Command Builder variable
Dim cb As New OleDb.OleDbCommandBuilder(TestDataAdapter)

Dim strText, strNewText As String

'Clear Dataset from last operation

' Fill the data
TestDataAdapter.Fill(TestDataSet, "TestTable")

' Determine how many rows are in the dataset
MaxRows = TestDataSet.Tables("TestTable").Rows.Count

'Make sure we are not going past the last row in the dataset
inc = -1

'Display information
If inc <> MaxRows - 1 Then
inc = inc + 1

'this is the String to Search in
strText = txtField4.Text

' Remove all the "/", "-", "()", space, and "," characters
strNewText = strText.Replace("/", "")
strNewText = strNewText.Replace("-", "")
strNewText = strNewText.Replace(",", "")
strNewText = strNewText.Replace(" ", "")
strNewText = strNewText.Replace("(", "")
strNewText = strNewText.Replace(")", "")

txtField4.Text = strNewText
TestDataSet.Tables("TestTable").Rows(inc).Item("field1") = txtField1.Text
TestDataSet.Tables("TestTable").Rows(inc).Item("field2") = txtField2.Text
TestDataSet.Tables("TestTable").Rows(inc).Item("field3") = txtField3.Text
TestDataSet.Tables("TestTable").Rows(inc).Item("field4") = txtField4.Text
TestDataSet.Tables("TestTable").Rows(inc).Item("field5") = txtField5.Text
TestDataSet.Tables("TestTable").Rows(inc).Item("field6") = txtField6.Text
TestDataSet.Tables("TestTable").Rows(inc).Item("field7") = txtField7.Text
TestDataSet.Tables("TestTable").Rows(inc).Item("field8") = txtField8.Text
TestDataSet.Tables("TestTable").Rows(inc).Item("field9") = txtField9.Text

' Update the database
TestDataAdapter.Update(TestDataSet, "TestTable")
MsgBox("Data updated")
MsgBox("No more rows")
End If

End Sub
Private Sub NavigateRecords()

txtField1.Text = TestDataSet.Tables("TestTable").Rows(inc).Item("field1")
txtField2.Text = TestDataSet.Tables("TestTable").Rows(inc).Item("field2")
txtField3.Text = TestDataSet.Tables("TestTable").Rows(inc).Item("field3")
txtField4.Text = TestDataSet.Tables("TestTable").Rows(inc).Item("field4")
txtField5.Text = TestDataSet.Tables("TestTable").Rows(inc).Item("field5")
txtField6.Text = TestDataSet.Tables("TestTable").Rows(inc).Item("field6")
txtField7.Text = TestDataSet.Tables("TestTable").Rows(inc).Item("field7")
txtField8.Text = TestDataSet.Tables("TestTable").Rows(inc).Item("field8")
txtField9.Text = TestDataSet.Tables("TestTable").Rows(inc).Item("field9")

End Sub

End Class

Thank you for your helps in advance,

Vy Nguyen

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!