Click here to Skip to main content
15,881,657 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
VB
Private Sub btnedit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnedit.Click
    connect.Open()
    Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand("SELECT * FROM tbluser", connect)
    sql = "update tbluser set  Username ='" & TextBox2.Text & "', Password ='" & TextBox3.Text & "', Userlevel ='" & ComboBox1.Text & "'where IDnumber= '" & TextBox1.Text & "'"
    cmd = New OleDb.OleDbCommand(sql, connect)
    cmd.ExecuteNonQuery()
    connect.Close()
    MsgBox("Updated")
End Sub

Private Sub btndelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndelete.Click
    connect.Open()
    Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand("Select * from tbluser where IDnumber ='" & TextBox1.Text & "'", connect)
    Dim sdr As OleDb.OleDbDataReader = cmd.ExecuteReader
    If (MsgBox("Are you sure you want to delete this record?", vbOKCancel) = vbOK) Then
        sql = "Delete * from tblUser where userid='" & TextBox1.Text & "'"
        cmd = New OleDb.OleDbCommand(sql, connect)
        cmd.ExecuteNonQuery()
        connect.Close()
    Else
        MsgBox("Operation Cancelled")
        connect.Close()
        Exit Sub
    End If
End Sub
Posted
Comments
Sergey Alexandrovich Kryukov 6-Mar-15 9:06am    
In what line?
—SA
Member 11475835 6-Mar-15 11:51am    
cmd.ExecuteNonQuery()in the edit button
Dim sdr As OleDb.OleDbDataReader = cmd.ExecuteReader in the delete button

1 solution

You should use Parameterized Query technique instead of inline query. It not only helps you to pass the parameter with appropriate datatype, but also prevents the application from SQL Injection Attacks.

Refer - Using Parameterized queries to prevent SQL Injection Attacks in SQL Server[^].
 
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