Function Authenticate(ByVal UserName As String, ByVal Password As String)
Dim con As New OleDbConnection(connectionstring)
Dim cmdstring As String
cmdstring = "SELECT username, password FROM tblUsers where username = @user AND password = @pass"
con.Open()
Dim cmd As OleDbCommand = New OleDbCommand(cmdstring, con)
cmd.Parameters.AddWithValue("@user", OleDbType.VarChar).Value = UserName
cmd.Parameters.AddWithValue("@pass", OleDbType.VarChar).Value = Password
Dim sdr As OleDbDataReader = cmd.ExecuteReader()
If (sdr.HasRows) Then
Authenticate = True
Else
Authenticate = False
End If
sdr.Close()
con.Close()
con = Nothing
Return Authenticate
End Function
Can anybody help, not sure why I’m getting A scalar variable '@user' needs to be declared as soon as I hit this line:
Dim sdr As OleDbDataReader = cmd.ExecuteReader()
The answer is as follows
For some reason, the ? in the queries does the trick, also the addwithvalues adds the values in the respected ? in the query, took me a while to find this, so i thought that i would share 🙂