jaklotz
August 18th, 2005, 08:15 PM
Hi - can anyone help with this?
Here is my code on my codebehind page that tries to check a user's login:
Private Sub Login_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Login.Click
'perform database check here
Dim sPassword$, sUserName$
Dim cn As New OleDbConnection(Session("SQLConn"))
Dim cmd As New OleDbCommand
Dim dr As OleDbDataReader
cn.Open()
cmd.Connection = cn
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "UsersLoginCheck"
cmd.Parameters.Add("@UserName", txtUserName.Text)
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
dr.Read()
If dr.Read() Then
lblLoginMessage.Text = "Invalid Username!"
sPassword = dr("Password")
If txtPassword.Text = sPassword Then
Session("gblUserID") = dr("UserID")
Session("gblUserName") = dr("UserName")
Else
lblLoginMessage.Text = "Invalid Password!"
End If
Else
lblLoginMessage.Text = "Invalid Username!"
End If
dr.Close()
cn.Close()
End Sub
The problem is, even though I know the data exists in the table in the db, the data reader doesn't have it - I get this in my watch window:
dr("UserID") Run-time exception thrown : System.InvalidOperationException - No data exists for the row/column.
I know a record exists for my username that I passed in - why do I get this error??
HELP!!
Here is my code on my codebehind page that tries to check a user's login:
Private Sub Login_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Login.Click
'perform database check here
Dim sPassword$, sUserName$
Dim cn As New OleDbConnection(Session("SQLConn"))
Dim cmd As New OleDbCommand
Dim dr As OleDbDataReader
cn.Open()
cmd.Connection = cn
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "UsersLoginCheck"
cmd.Parameters.Add("@UserName", txtUserName.Text)
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
dr.Read()
If dr.Read() Then
lblLoginMessage.Text = "Invalid Username!"
sPassword = dr("Password")
If txtPassword.Text = sPassword Then
Session("gblUserID") = dr("UserID")
Session("gblUserName") = dr("UserName")
Else
lblLoginMessage.Text = "Invalid Password!"
End If
Else
lblLoginMessage.Text = "Invalid Username!"
End If
dr.Close()
cn.Close()
End Sub
The problem is, even though I know the data exists in the table in the db, the data reader doesn't have it - I get this in my watch window:
dr("UserID") Run-time exception thrown : System.InvalidOperationException - No data exists for the row/column.
I know a record exists for my username that I passed in - why do I get this error??
HELP!!