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.
 

Ruffnekk

Member
Joined
Mar 17, 2005
Messages
17
Location
Rotterdam, Netherlands
Programming Experience
10+
Please post the code where you construct the UpdateCommand and relevant things, because no-one will be able to help you this way (too general).
 

odelya

Member
Joined
Mar 13, 2005
Messages
10
Programming Experience
Beginner
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
 

Ruffnekk

Member
Joined
Mar 17, 2005
Messages
17
Location
Rotterdam, Netherlands
Programming Experience
10+
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()
 

odelya

Member
Joined
Mar 13, 2005
Messages
10
Programming Experience
Beginner
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
 
Top Bottom