Question UPDATE - row doesnt change

Abdalltif

New member
Joined
Dec 13, 2013
Messages
4
Programming Experience
1-3
Hello
I did a code that will update a record in some table from vb.net
VB.NET:
            Try                conn.Open()
                Dim cmdUpdate As New OleDbCommand
                cmdUpdate.Connection = conn
                cmdUpdate.CommandText = "UPDATE nurses SET num_n='@a1', name_n='@a2' , id_n='@a3' , birth_n='@a4', sex_n='@a5', nationality_n='@a6',   salary_n='@a7', note_n='@a8' WHERE num_n='@a1' "
                cmdUpdate.Parameters.AddWithValue("@a1", TxtNum.Text)
                cmdUpdate.Parameters.AddWithValue("@a2", txtName.Text)
                cmdUpdate.Parameters.AddWithValue("@a3", txtId.Text)
                cmdUpdate.Parameters.AddWithValue("@a4", datep.Value.Date)
                cmdUpdate.Parameters.AddWithValue("@a5", radioSex.Checked)
                cmdUpdate.Parameters.AddWithValue("@a6", 1)
                cmdUpdate.Parameters.AddWithValue("@a7", txtSalary.Text)
                cmdUpdate.Parameters.AddWithValue("@a8", txtNotes.Text)


                cmdUpdate.ExecuteNonQuery()
                MsgBox("Done")


            Catch ex As Exception
                MsgBox( ex.Message)
            End Try
            conn.Close()

Everything went nicely with no error to show me the msg "Done"
But after I open my database I found my database the row doesnt changed
who can figure it out for me ?
 
Hi and welcome to the Forum,

The first thing to do is to get rid of the Single Quotes around the Parameter Names defined within your query. They will be treated a Strings as you have things now as apposed to being treated as the correct data type that each of the parameters represent.

The next thing is to NOT try and Update the field on which you are searching on since a search on a field implies that this value already exists in the DataSource.

Give these two points a try first and post back if you are still having problems.

Hope that helps.

Cheers,

Ian
 
Back
Top