can not update commnad

odelya

Member
Joined
Mar 13, 2005
Messages
10
Programming Experience
Beginner
i am tryning to update my access database, but i get this error message:

An unhandled exception of type 'System.InvalidOperationException' occurred in system.data.dll
Additional information: Update requires a valid UpdateCommand when passed DataRow collection with modified rows.
 
what i wrote

i didn't understand the answer there. is there something less complicated?
i wrote like that:
sql = "update categories set checked = 1 where id=2"

datacmd = New OleDbCommand(sql, cnn)

datacmd.ExecuteNonQuery()

but at runtime I get:
An unhandled exception of type 'System.InvalidOperationException' occurred in system.data.dll
Additional information: Update requires a valid UpdateCommand when passed DataRow collection with modified
 
I think you need to include a data-adapter, like this:

VB.NET:
    Dim SQL As String = "UPDATE [Categories] SET [Checked] = 1 WHERE [ID] = 2;"
    Dim Cnn As New OleDbConnection("Your connectionstring")
    Dim DA As New OleDbDataAdapter
    Dim CMD As New OleDbCommand(SQL, Cnn)

    Cnn.Open()
    DA.UpdateCommand = CMD
    DA.UpdateCommand.ExecuteNonQuery()
    Cnn.Close()

    DA.Dispose()
    CMD.Dispose()
    Cnn.Dispose()
 
doesnt help

i still get the message:
(i had the dataadopter!)
An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll
 
Back
Top