help trying to create a login form

Krypton

New member
Joined
Mar 16, 2008
Messages
1
Programming Experience
Beginner
Hi everybody, I read some of the threads and you guys seem to know what you are doing. Maybe one of you can help me with the following problem?

I have a table in my access 2007 database that stores login details and I am trying to create a login form in Visual Studio. I have connected to the database but I am not sure about the code that compares the details the user puts into the textboxes to the details stored in the database.
This is what I have so far, if I understand correctly the compare method goes where it currently has *****

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim objConnection As New OleDbConnection(strConnection)
objConnection.Open()
Dim strSQL As String = "SELECT * FROM tblAdmin"
Dim objCommand As New OleDbCommand(strSQL, objConnection)

Dim objReader As OleDbDataReader
objReader = objCommand.ExecuteReader

If objConnection.State = ConnectionState.Open Then
If objReader.HasRows Then
if
******
End If

Else
MessageBox.Show("Error has occured", _
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End If



Thanks in advance
 
For reasons that I've posted here, this is a better method...

Dim strSQL As String = "SELECT ID FROM tblAdmin WHERE Username='" & txtUserName.Text.Replace("'","''") & "' AND Password='" & txtPassword.Text.Replace("'","''") & "'"
Dim objCommand As New OleDbCommand(strSQL, objConnection)


Dim objReader As OleDbDataReader
objReader = objCommand.ExecuteReader

If objConnection.State = ConnectionState.Open Then
If objReader.HasRows Then
'logged in - there was a row with the right username and password
end if
Else
MessageBox.Show("Error has occured", _
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End If
 
wizzardmr42, use Parameters when creating a Sql command. Adding strings together can get you in all sorts of trouble, it's the worst advice you can give db newbies. (It's like using reflection and Object type for all your code. which you don't.) See for example this post.
 
Oops. Sorry about that - I usually don't use DB Commands because I have my own query building code so I forgot command objects can take parameters because I haven't used them for so long!
 
Read the DW2 link in my signature, for info on how to do data access properly.. start with Creating a simple data app.
 
This looks like another homework one, but at least this guy seems to have made an effort!
 
Back
Top