Problem: How to do an MS Access DLookUp() in ASP/VB.NET?

Question: How to do an MS Access DLookUp() in ASP/VB.NET?

Hello – I’m a MS Access guy crossing over into ASP.NET (v2.0), and I’d like to know the best way to do a simple lookup in a table, using one value to get another, like an Access DLookUp() function.

Specifically, in the Authenticate event of a Login control, I need to go get the account # associated with that users’ UserName, stored in an Access table.

Thanks


 

Solution: How to do an MS Access DLookUp() in ASP/VB.NET?

Dim prtConn As New OleDb.OleDbConnection(“your odbc connection string here”)
prtConn.Open()
Dim prtCmd As OleDb.OleDbCommand
prtCmd = New OleDbCommand(“SELECT count(*) FROM [Customer] WHERE username = @username and password = @password”, prtConn)
prtCmd.Parameters.Add(New OleDbParameter(“@username”, OleDbType.VarChar, 40))
prtCmd.Parameters.Add(New OleDbParameter(“@password”, OleDbType.VarChar, 40))
prtCmd.Parameters(“@username”).Value = txtusername.Text
prtCmd.Parameters(“@password”).Value = txtpassword.Text
Dim result As Integer = 0
result = prtCmd.ExecuteScalar
prtConn.Close()

If result = 1 Then
‘found username and password in database!
End If