-
ASP.NET (
http://www.daniweb.com/forums/forum18.html)
| chrispaul8676 | Jul 6th, 2009 7:05 am | |
| Session error in asp net hi,
there , i am coming up with a login page and i am having error when i run the programme. It says 'Invalid attempt to read when no data is present'.
Session("ses_uname") = rdr("FirstName") + " " + rdr("LastName")
Imports System.Data.Sql
Imports System.Data.SqlClient
Imports System.Web
Partial Class _Default
Inherits System.Web.UI.Page
Dim str As String = ConfigurationManager.ConnectionStrings("CourierSystemConnectionString").ConnectionString
Dim con As SqlConnection
Dim cmd As SqlCommand
Dim rdr As SqlDataReader
Dim sql As String
Dim t As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnlogin.Click
con = New SqlConnection(str)
con.Open()
Dim type As String
type = ddltype.SelectedValue
If type = "Customer" Then
sql = "select * from CusRegis_Table where CusID='" + tuname.Text + "' and password2='" + tupass.Text + "'"
Else
sql = "select * from StaffRegis_Table where StaffID='" + tuname.Text + "' and Password='" + tupass.Text + "'"
End If
cmd = New SqlCommand(sql, con)
rdr = cmd.ExecuteReader
If rdr.HasRows Then
If ddltype.SelectedValue = "Customer" Then
Session("ses_dname") = rdr("CusFName") + " " + rdr("CusLName")
Session("ses_uid") = rdr("Cusid")
Response.Redirect("Home1.aspx")
'ElseIf
' ddltype.SelectedValue = "Delivery Boy" Then
' Session("ses_dname") = rdr("FirstName") + " " + rdr("Lastname")
' Session("ses_uid") = rdr("staffid")
'Session("ses_utype") = rdr("Designation")
'Response.Redirect("DeliveryBoyDirection.aspx")
Else
ddltype.SelectedValue = "DeliveryBoy"
Session("ses_uname") = rdr("FirstName") + " " + rdr("LastName") Session("ses_uid") = rdr("staffid")
Session("ses_utype") = rdr("Designation")
Response.Redirect("DeliveryBoyDirection.aspx")
End If
End If
End Sub
End Class |
| mail2saion | Jul 7th, 2009 3:14 am | |
| Re: Session error in asp net Include the read method first.
rdr.read();
if(rdr.hasrows)
.............................. |
| chrispaul8676 | Jul 8th, 2009 2:49 am | |
| Re: Session error in asp net thank you for replying.
I am not sure where to key in the read method |
| Ramesh S | Jul 8th, 2009 3:03 am | |
| Re: Session error in asp net Just change 'If rdr.HasRows' to 'If rdr.Read()'
Therefore your code should be as follows
If rdr.Read() Then
If ddltype.SelectedValue = "Customer" Then
Session("ses_dname") = rdr("CusFName") + " " + rdr("CusLName")
Session("ses_uid") = rdr("Cusid")
Response.Redirect("Home1.aspx")
'ElseIf
' ddltype.SelectedValue = "Delivery Boy" Then
' Session("ses_dname") = rdr("FirstName") + " " + rdr("Lastname")
' Session("ses_uid") = rdr("staffid")
'Session("ses_utype") = rdr("Designation")
'Response.Redirect("DeliveryBoyDirection.aspx")
Else
ddltype.SelectedValue = "DeliveryBoy"
Session("ses_uname") = rdr("FirstName") + " " + rdr("LastName") Session("ses_uid") = rdr("staffid")
Session("ses_utype") = rdr("Designation")
Response.Redirect("DeliveryBoyDirection.aspx")
End If
End If |
| dnanetwork | Jul 10th, 2009 3:56 am | |
| Re: Session error in asp net i think you are VB.net...but i'm the C# guy...
i guess you are missing toSting() function which is required...
in your code instead storing the string,you are storing the reader object...
string finaltext = rdr["FirstName"].tostring() + "" + rdr["LastName"].toString();
Session.add("ses_uname",) = rdr("FirstName") + " " + rdr("LastName")
hope it helps...and if i'm wrong please let me know... |
| All times are GMT -4. The time now is 9:04 pm. | |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC