Hallo good people of Stack overflow. For some reason i want to keep working with ms Access as the database using vb net.
My code works well but only if i work directly with user inputs. Which makes my system prone to sql injections.
I have seen some examples on google that show use binding of parameters in prepared statements using vbn.et.
Unfortunately those examples do not support "Provider" key word in my connection string for ms Access table.
Can someone who understands this help me modify my vb code below to work with binding of parameters using Provider=Microsoft.Jet.OLEDB.4.0 as connection string?
I want to avoid saying "where password = " & supplier_password but say something like "where password = @supplier_password " and later provide the supplied password text.
Here is my vb net code.
Private Sub test_password()
Dim myConnection As OleDbConnection = New OleDbConnection
myConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source =C:\books\author.mdb"
Dim counter As Int16
myConnection.Open()
Dim str As String
str = "SELECT * FROM users where password = '" & pass.Text & "'"
Dim cmd As OleDbCommand = New OleDbCommand(str, myConnection)
counter = cmd.ExecuteScalar
myConnection.Close()
If counter > 0 Then
MsgBox("password was found")
Else
MsgBox("password was NOT found")
End If
End Sub
I have used the appropriate
Imports System.Data.OleDb
Imports System.Data.SqlClient
Many thanks