Login: - Compare User name in texbox to database

a02227

Member
Joined
Nov 30, 2004
Messages
15
Location
Ireland
Programming Experience
Beginner
I'm trying to compare a user name entered into a textbox and searching to see if it is entered into the database, can anyone tell me if i'm heading in the right direction or completely wrong. At the min its not working, so any help would be much appreciated.

Function Search()

Dim cmd As New OleDb.OleDbCommand
Try

Me.OleDbConnection1.Open()
cmd.Connection = OleDbConnection1
cmd.Parameters.Add("@Membership No", Me.txtUser.text)
cmd.CommandType = CommandType.Text
cmd.CommandText = "Select * from Members Where (Membership No = @Membership No)"
reader = cmd.ExecuteReader
reader.Read()
reader.Read.CompareTo(txtUser)
Return True
Catch ex As Exception
Response.Redirect("IncorrectUser.aspx")
End Try


Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
If Search(True) Then
Response.Redirect("MembersPage.aspx")
End If
End Sub
 

yfng

Member
Joined
Feb 23, 2005
Messages
13
Programming Experience
Beginner
The code seems have problems...

membership no with space?

if reader.read.compareto(txtuser) = 0 then
return true
else
return false
end if

if search() then
 

Schenz

Well-known member
Joined
Sep 11, 2004
Messages
181
Location
Cincinnati, OH
Programming Experience
5-10
Since the redirect is in the catch part of A Try - Catch, it means that an exception was thrown. Why not do a response.write to see what the exception is rather than rediret to the Incorrect page?

VB.NET:
 Function Search() as Boolean
 
         Dim cmd As New OleDb.OleDbCommand
         Try
 
             Me.OleDbConnection1.Open()
             cmd.Connection = OleDbConnection1
             cmd.Parameters.Add("@Membership No", Me.txtUser.text)
             cmd.CommandType = CommandType.Text
             cmd.CommandText = "Select * from Members Where (Membership No = @Membership No)"
             reader = cmd.ExecuteReader
             reader.Read()
             reader.Read.CompareTo(txtUser)
             Return True
         Catch ex As Exception
             Response.Write(ex.ToString)
         End Try
 End Function

 Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
         If Search(True) Then
             Response.Redirect("MembersPage.aspx")
         End If
     End Sub
 
Top Bottom