Update requires a valid UpdateCommand

coleman01

Member
Joined
Apr 8, 2005
Messages
11
Programming Experience
Beginner
Hi,

I have a .net / ado application (with an access database).

I can get it to read into the dataset and display records in a list box etc but when I go to update a password (a field within a table) I get this error...

Additional information: Update requires a valid UpdateCommand when passed DataRow collection with modified rows.

The code i used for updating is:

usersDataSet.Tables("users").Rows(lstUsers.SelectedIndex).Item(2) = "password"

dbUsers.Update(usersDataSet, "users")

MsgBox("Done")

Any ideas from anyone as to why it wont update the actual database?

Many thanks.
Chris
 
Hi,
U need to specify the UpdateCommand of Dataadapter before calling dbUsers.Update.......

here is sample ........(It's using sqlDataadapter ...........)

Dim da As SqlDataAdapter = New SqlDataAdapter()
Dim cmd As SqlCommand
' Create the SelectCommand.

' Create the InsertCommand.
cmd = New SqlCommand("UPDATE USER SET columnname=@Password, conn)
cmd.Parameters.Add("@password", SqlDbType.NChar, 50, "Columnname")
da.UpdateCommand = cmd
da.Update(usersDataSet, "users")

I hope this will help u....................

Regards,
Ritesh
 
or you could use the commandbuilder thingy it will do all your updates,insert,delete and be sure you have a primary key of your table so that the commandbuilder will work.
 
Back
Top