Click here to Skip to main content
15,890,336 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i want to save all changes made in datagridview by clicking a button,i used access 2007, i used the code below but error display "Update Requires a valid UpdateCommand when passed Datarow collection with modified Rows"

VB
Dim i As Integer
        Try
            i = da.Update(ds, "WorkRecords")
            MsgBox("Records Updated= " & i)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try


Any Help will be appreciated.
Thanks!
Posted
Updated 28-Oct-14 21:15pm
v5
Comments
Sinisa Hajnal 29-Oct-14 4:55am    
What is the update command of your adapter?

It's quite often asked question. Please see here[^].
 
Share this answer
 
v2
Try this code it works for me.
Dim i As Integer ' The variable i gives the number of records updated
       'create a table
       Dim dt As New DataTable
       ' create a data adapter
       Dim da As New OleDbDataAdapter
       Try
           'retrieving and populating datagridview
           '***************************************
           ' your statements
           '***************************************

           'Populates the datatable
           da.Fill(dt)
           'DataBindings
           Your_DataGridView.DataSource = dt
           i = da.Update(ds, "WorkRecords")
           MsgBox("Changes made successfully, " & i & " records updated!", MsgBoxStyle.OkOnly, "Success")

       Catch ex As Exception
           MsgBox(ex.Message)
       End Try
 
Share this answer
 
Comments
TheHellGirl 29-Oct-14 22:41pm    
i tried your code but error display "Update Requires a valid UpdateCommand when passed Datarow collection with modified Rows"

Dim i As Integer ' The variable i gives the number of records updated
'create a table
Dim dt As New DataTable
' create a data adapter
Dim da As New OleDbDataAdapter
Try
str = "Select * from WorkRecords"
da = New OleDbDataAdapter(str, conn)
da.Fill(ds, "WorkRecords")
DataGridView2.DataSource = ds.Tables(0)

'Populates the datatable
da.Fill(dt)
'DataBindings
DataGridView2.DataSource = dt
i = da.Update(ds, "WorkRecords")
MsgBox("Changes made successfully, " & i & " records updated!", MsgBoxStyle.OkOnly, "Success")

Catch ex As Exception
MsgBox(ex.Message)
End Try

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900