954,515 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Update command not working

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.

satmad123
Newbie Poster
2 posts since Oct 2008
Reputation Points: 10
Solved Threads: 0
 

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

Teme64
Veteran Poster
1,031 posts since Aug 2008
Reputation Points: 218
Solved Threads: 203
 

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..........

satmad123
Newbie Poster
2 posts since Oct 2008
Reputation Points: 10
Solved Threads: 0
 

is there any condition to execute the block of code ?

debasisdas
Posting Genius
6,872 posts since Feb 2007
Reputation Points: 666
Solved Threads: 434
 

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

Teme64
Veteran Poster
1,031 posts since Aug 2008
Reputation Points: 218
Solved Threads: 203
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You