Click here to Skip to main content
15,890,717 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
connect.ConnectionString = "Provider=Microsoft.jet.OLEDB.4.0; data source = |datadirectory|/Lecture1.mdb"
connect.Open()
Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand("Select * FROM StudentInfo", connect)
sql = "update Lecture1 set age = ' " & TextBox5.Text & " ' , Gender=' " & TextBox4.Text & " ' , Scourse ='" & TextBox3.Text & "', Sname ='" & TextBox2.Text & "' , where Srec='" & TextBox1.Text & " ' "
cmd = New OleDb.OleDbCommand(sql, connect)
cmd.ExecuteNonQuery()
connect.Close()
MsgBox("Updated")
Posted

1 solution

You never want to write code like this because your database can be damaged and/or hijacked by sql injection.

Instead please use code similar to:

C#
sql = "UPDATE Lecture1 SET age = @age, Gender = @Gender..."
cmd.Parameters.AddWithValue("@age", TextBox5.Text);
cmd.Parameters.AddWithValue("@Gender", TextBox4.Text);
...


Also, do not leave the default control ids. Having all your textboxes named TextBoxx makes debugging much harder. It's very quick and easy to give them meaningful IDs: txtAge, txtGender. You'll thank yourself later on.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900