umd = New OleDbCommand()
umd.CommandText = "UPDATE STUDENT SET roll = ' " + TextBox1.Text + " ' , name = ' " + TextBox2.Text + " ', marks = ' " + TextBox3.Text + " ' " & " WHERE roll = ' " + TextBox1.Text + " ' "
umd.Connection = con
con.Open()
umd.ExecuteNonQuery()
da.UpdateCommand = umd

con.Close()
ds.Clear()
da.Fill(ds, "student")

I am using the above code for updating a row in database (MS access) but its not working. Please help me in solving this. Thanx.

Recommended Answers

All 4 Replies

Which part is not working? What error do you get?

At least using TextBox1.Text in both SET and WHERE seems a bit suspicious. If roll exists, you update roll-field with the same value it already has. If roll does not exists, then your update fails.

Also, open connection before you assign it to command:
con.Open()
umd.Connection = con

It is still the same.......I have removed the roll field from update and also I have opened connection before assigning it to a command..........

is there any condition to execute the block of code ?

Do you get an error message? Or does your code "work" i.e. no error message, but the database will not be updated?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.