LennieKuah 0 Light Poster

Hi there,
When I add a new row into the DataSet, the first time it works good but after the first time I added another row it's not working instead it generate this error message :
"Update requires a valid Insertcommand when passed datarow collection with new rows"

This is where it generates that error message after the first time:
oleDA.Update(oleDS.Tables("BOOK")) 'update DataSet

Here are the overall Scripts:
Private oleSqlConn As OleDbConnection
Private oleSqlCmd As OleDbCommand

Private oleDA As OleDbDataAdapter
Private oleDS As DataSet = New DataSet
Private connStr As String

'CLASS Instantiate
Dim clsAdoConn As clsAdoConnection = New clsAdoConnection

'Bound - DataBindingManager Instantiate
Private objDBMBook As BindingManagerBase ' binding manager for dataset

Private Sub BtnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSave.Click

'Save updates to the dataset
Dim dsNewRow As DataRow

If FCheckData() = True Then
Try

'New Row creation and ADD in DataSet.
If ActionType.ToUpper = "ADD" Then
dsNewRow=oleDS.Tables"Book").NewRow

'fill dataset row with textbox data
dsNewRow.Item("ISBN") = txtISBN.Text
dsNewRow.Item("Title") = txtTitle.Text
dsNewRow.Item("Author") = txtAuthor.Text
dsNewRow.Item("Publisher") = txtPublisher.Text
dsNewRow.Item("SubjectCode") = txtSubject.Text
dsNewRow.Item("ShelfLocation") = txtShelfLocation.Text
dsNewRow.Item("Fiction") = IIf(Me.ChkFiction.Checked = False, 0, 1)
End If

oleDA.Update(oleDS.Tables ("BOOK"))
oleDS.Tables("Book").AcceptChanges()
objDBMBook.EndCurrentEdit()

Catch ex As Exception
MessageBox.Show(ex.Message, "SAVE RECORD")


End Try
End If
End Sub

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.