can I use this to update the database?

zacksofia

Member
Joined
Jul 10, 2005
Messages
10
Programming Experience
Beginner
[RESOLVED] can I use this to update the database?

Hello guys,

I know that this question have been asked thousand times but I really need some explanation here. I created a form, 2 buttons and textboxes.
The user can only view their info when the form load. i have added 2 buttons that enable user to edit the data but only certain data are allowed which are address, contact number and email. I wrote this code but nothing happen to the database.

I wanted to update email, address and contact number of a particular row.

I know something missing here but I'm not sure what is it.


OleDbConnection1.Open()

Dim mycmd AsNew OleDbCommand("UPDATE STUDENT SET Address = @Address, email = @email, contact_num = @contact_num WHERE Stud_ID = @Stud_ID", OleDbConnection1)

mycmd.Parameters.Add("@Address", txtaddress.Text)

mycmd.Parameters.Add("@email", txtemail.Text)

mycmd.Parameters.Add("@contact_num", txtcontact.Text)

Try

mycmd.ExecuteNonQuery()

Catch ex As Exception

EndTry

OleDbConnection1.Close()

 
Last edited:
You created parameters for Address, Email, and ContactNum... but not Stud_ID.

Tg
 
thanks for the reply.

I have created parameters for Stud_ID but still nothing happen in the database.

Dim mycmd As New OleDbCommand("UPDATE STUDENT SET Address = @Address, email = @email, contact_num = @contact_num WHERE Stud_ID = @Stud_ID", OleDbConnection1)

mycmd.Parameters.Add("@Stud_ID", OleDbType.VarChar).Value =
Me.lblstudId2.Text

mycmd.Parameters.Add("@Address", OleDbType.VarChar).Value =
Me.txtaddress.Text

mycmd.Parameters.Add("@email", OleDbType.VarChar).Value =
Me.txtemail.Text

mycmd.Parameters.Add("@contact_num", OleDbType.VarChar).Value =
Me.txtcontact.Text



OleDbConnection1.Open()

Try

mycmd.ExecuteNonQuery()



Catch ex As Exception

End Try

OleDbConnection1.Close()

What went wrong?
 
Create your parameters in the same order they are in the SQL.... in other words, create your stud_id parameter last.

Tg
 
Back
Top