Update Command error

Even if I create a new record, after entering contact details I get this error message:

update requires a valid updatecommand when passed datarow collection with modified rows error

The problem is made worse from the fact that my code was mainly created using the wizard and I havent changed any of the update coding

here is my code:

 Private idno As Integer

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.BindingContext(objdsCustomers, "Customers").CancelCurrentEdit()
        Me.objdsCustomers_PositionChanged()

    End Sub
    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        Me.BindingContext(objdsCustomers, "Customers").Position = (Me.objdsCustomers.Tables("Customers").Rows.Count - 1)
        Me.objdsCustomers_PositionChanged()
        idno = Val(Label1.Text) + 1
        'Clear out the current edits
        Me.BindingContext(objdsCustomers, "Customers").EndCurrentEdit()
        Me.BindingContext(objdsCustomers, "Customers").AddNew()
        Label1.Text = idno
        editConfirmedDate.Text = Date.Today
        editCorfirmedStatus.Text = "Yes"
        editReminderDate.Text = Date.Today.AddDays(14)
        editReminderStatus.Text = "Yes"
        editFinalDate.Text = Date.Today.AddDays(21)
        editFinalStatus.Text = "No"
        editD1Date.Text = Date.Today.AddDays(28)
        editD1Status.Text = "No"
        editD2Date.Text = Date.Today.AddDays(35)
        editD2Status.Text = "No"
        editInvoiceNumber.Text = idno + 3000
        editPaymentType.Text = "Pending"
        editDateChanged.Text = Date.Today
        editSizePurchased.Text = ""
        editDiscount.Text = "0"
        editVAT.Text = "0"
        editPOP.Text = "No"
        Me.objdsCustomers_PositionChanged()

    End Sub
    Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
        Try
            'Attempt to update the datasource.
            Me.UpdateDataSet()
        Catch eUpdate As System.Exception
            'Add your error handling code here.
            'Display error message, if any.
            System.Windows.Forms.MessageBox.Show(eUpdate.Message)
        End Try
        Me.objdsCustomers_PositionChanged()
    End Sub
    Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Try
            'Attempt to load the dataset.
            Me.LoadDataSet()
        Catch eLoad As System.Exception
            'Add your error handling code here.
            'Display error message, if any.
            System.Windows.Forms.MessageBox.Show(eLoad.Message)
        End Try
        Me.objdsCustomers_PositionChanged()

    End Sub
    Private Sub btnNavFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNavFirst.Click
        Me.BindingContext(objdsCustomers, "Customers").Position = 0
        Me.objdsCustomers_PositionChanged()

    End Sub
    Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLast.Click
        Me.BindingContext(objdsCustomers, "Customers").Position = (Me.objdsCustomers.Tables("Customers").Rows.Count - 1)
        Me.objdsCustomers_PositionChanged()

    End Sub
    Private Sub btnNavPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNavPrev.Click
        Me.BindingContext(objdsCustomers, "Customers").Position = (Me.BindingContext(objdsCustomers, "Customers").Position - 1)
        Me.objdsCustomers_PositionChanged()

    End Sub
    Private Sub btnNavNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNavNext.Click
        Me.BindingContext(objdsCustomers, "Customers").Position = (Me.BindingContext(objdsCustomers, "Customers").Position + 1)
        Me.objdsCustomers_PositionChanged()

    End Sub
    Private Sub objdsCustomers_PositionChanged()
        Me.lblNavLocation.Text = (((Me.BindingContext(objdsCustomers, "Customers").Position + 1).ToString + " of  ") _
                    + Me.BindingContext(objdsCustomers, "Customers").Count.ToString)

    End Sub
    Public Sub UpdateDataSet()
        'Create a new dataset to hold the changes that have been made to the main dataset.
        Dim objDataSetChanges As MDP.dsCustomers = New MDP.dsCustomers
        'Stop any current edits.
        Me.BindingContext(objdsCustomers, "Customers").EndCurrentEdit()
        'Get the changes that have been made to the main dataset.
        objDataSetChanges = CType(objdsCustomers.GetChanges, MDP.dsCustomers)
        'Check to see if any changes have been made.
        If (Not (objDataSetChanges) Is Nothing) Then
            Try
                'There are changes that need to be made, so attempt to update the datasource by
                'calling the update method and passing the dataset and any parameters.
                Me.UpdateDataSource(objDataSetChanges)
                objdsCustomers.Merge(objDataSetChanges)
                objdsCustomers.AcceptChanges()
            Catch eUpdate As System.Exception
                'Add your error handling code here.
                Throw eUpdate
            End Try
            'Add your code to check the returned dataset for any errors that may have been
            'pushed into the row object's error.
        End If

    End Sub
    Public Sub LoadDataSet()
        'Create a new dataset to hold the records returned from the call to FillDataSet.
        'A temporary dataset is used because filling the existing dataset would
        'require the databindings to be rebound.
        Dim objDataSetTemp As MDP.dsCustomers
        objDataSetTemp = New MDP.dsCustomers
        Try
            'Attempt to fill the temporary dataset.
            Me.FillDataSet(objDataSetTemp)
        Catch eFillDataSet As System.Exception
            'Add your error handling code here.
            Throw eFillDataSet
        End Try
        Try
            'Empty the old records from the dataset.
            objdsCustomers.Clear()
            'Merge the records into the main dataset.
            objdsCustomers.Merge(objDataSetTemp)
        Catch eLoadMerge As System.Exception
            'Add your error handling code here.
            Throw eLoadMerge
        End Try

    End Sub
    Public Sub UpdateDataSource(ByVal ChangedRows As MDP.dsCustomers)
        Try
            'The data source only needs to be updated if there are changes pending.
            If (Not (ChangedRows) Is Nothing) Then
                'Open the connection.
                Me.OleDbConnection1.Open()
                'Attempt to update the data source.
                OleDbDataAdapter1.Update(ChangedRows)
            End If
        Catch updateException As System.Exception
            'Add your error handling code here.
            Throw updateException
        Finally
            'Close the connection whether or not the exception was thrown.
            Me.OleDbConnection1.Close()
        End Try

    End Sub
    Public Sub FillDataSet(ByVal dataSet As MDP.dsCustomers)
        'Turn off constraint checking before the dataset is filled.
        'This allows the adapters to fill the dataset without concern
        'for dependencies between the tables.
        dataSet.EnforceConstraints = False
        Try
            'Open the connection.
            Me.OleDbConnection1.Open()
            'Attempt to fill the dataset through the OleDbDataAdapter1.
            Me.OleDbDataAdapter1.Fill(dataSet)
        Catch fillException As System.Exception
            'Add your error handling code here.
            Throw fillException
        Finally
            'Turn constraint checking back on.
            dataSet.EnforceConstraints = True
            'Close the connection whether or not the exception was thrown.
            Me.OleDbConnection1.Close()
        End Try

    End Sub

    Private Sub frmCustomers_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            'Attempt to load the dataset.
            Me.LoadDataSet()
        Catch eLoad As System.Exception
            'Add your error handling code here.
            'Display error message, if any.
            System.Windows.Forms.MessageBox.Show(eLoad.Message)
        End Try
        Me.objdsCustomers_PositionChanged()
    End Sub

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Me.UpdateDataSet()
        Me.Close()
    End Sub
    Friend WithEvents Label12 As System.Windows.Forms.Label

    Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
        Dim fp As New FormPrinting(Me)
        fp.PrintPreview = Me.CheckBoxPrintPreview.Checked
        fp.Orientation = FormPrinting.OrientationENum.Automatic
        fp.Orientation = FormPrinting.OrientationENum.Lanscape
        fp.Print()
    End Sub

    Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
        Call objdsCustomers_PositionChanged()
        Me.objdsCustomers.Clear()
        Me.OleDbDataAdapter1.SelectCommand.CommandText = "Select * from Customers where CustomerID like '%" & Trim(Me.txtSearch.Text) & "%'"
        Me.OleDbDataAdapter1.Fill(Me.objdsCustomers)
        Me.OleDbDataAdapter1.SelectCommand.CommandText = "Select * from Customers where CompanyName like '%" & Trim(Me.txtSearch.Text) & "%'"
        Me.OleDbDataAdapter1.Fill(Me.objdsCustomers)
        Me.OleDbDataAdapter1.SelectCommand.CommandText = "Select * from Customers where InvoiceNumber like '%" & Trim(Me.txtSearch.Text) & "%'"
        Me.OleDbDataAdapter1.Fill(Me.objdsCustomers)
        Call objdsCustomers_PositionChanged()
        btnAdd.Enabled = False
    End Sub

does anyone know how to help me   I am on msn using nycsavage@hotmail.com if anyone can help me.

thank you for your time


Answer this question

Update Command error

  • Update Command error