J
J Breckbill
Hello everyone,
I'm new to .net and I'm trying to figure out the ado.net. I'm creating a
login page for a new asp.net app. But I'm getting an error:
"System.Data ExecuteReader requires an open and available Connection. The
connection's current state is Closed." with the "If
DA.SelectCommand.ExecuteReader.HasRows = False Then" line of code if there
is no data returned.
If I don't check for no data, I get an error: "System.Data There is no row
at position 0."
Can you give me any hints with this?
thanks,
Jason
Try
Dim DS As New DataSet
Dim DR As DataRow
Dim strUsername As String
Dim strpassword As String
DA.SelectCommand.CommandText = "Select Username, Password from
tblFarmers where username='" & txtusername.Text.ToString & "'"
If DA.SelectCommand.ExecuteReader.HasRows = False Then
lblLoginFailed.Text = "--Login Failed. Username or Password
is invalid"
Exit Sub
End If
DA.Fill(DS)
DR = DS.Tables("tblFarmers").Rows(Session("Row1"))
strUsername = DR("username")
strpassword = DR("password")
If txtusername.Text.ToString = strUsername And
txtpassword.Text.ToString = strpassword Then
txtusername.Text = "Passed"
'Response.Redirect(strPassed)
Else
lblLoginFailed.Text = "Login Failed. Username or Password
is invalid"
End If
Catch
lblLoginFailed.Text = Err.Source & " " & Err.Description & " " &
Err.Erl
Err.Clear()
End Try
I'm new to .net and I'm trying to figure out the ado.net. I'm creating a
login page for a new asp.net app. But I'm getting an error:
"System.Data ExecuteReader requires an open and available Connection. The
connection's current state is Closed." with the "If
DA.SelectCommand.ExecuteReader.HasRows = False Then" line of code if there
is no data returned.
If I don't check for no data, I get an error: "System.Data There is no row
at position 0."
Can you give me any hints with this?
thanks,
Jason
Try
Dim DS As New DataSet
Dim DR As DataRow
Dim strUsername As String
Dim strpassword As String
DA.SelectCommand.CommandText = "Select Username, Password from
tblFarmers where username='" & txtusername.Text.ToString & "'"
If DA.SelectCommand.ExecuteReader.HasRows = False Then
lblLoginFailed.Text = "--Login Failed. Username or Password
is invalid"
Exit Sub
End If
DA.Fill(DS)
DR = DS.Tables("tblFarmers").Rows(Session("Row1"))
strUsername = DR("username")
strpassword = DR("password")
If txtusername.Text.ToString = strUsername And
txtpassword.Text.ToString = strpassword Then
txtusername.Text = "Passed"
'Response.Redirect(strPassed)
Else
lblLoginFailed.Text = "Login Failed. Username or Password
is invalid"
End If
Catch
lblLoginFailed.Text = Err.Source & " " & Err.Description & " " &
Err.Erl
Err.Clear()
End Try