| | |
Session error in asp net
Please support our ASP.NET advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
Thread Solved
![]() |
•
•
Join Date: Jul 2009
Posts: 36
Reputation:
Solved Threads: 0
hi,
there , i am coming up with a login page and i am having error when i run the programme. It says
Session("ses_uname") = rdr("FirstName") + " " + rdr("LastName")
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 Include the read method first.
rdr.read();
if(rdr.hasrows)
.............................. MARK AS SOLVED if its help you.
REGARDS
MCTS - Shawpnendu bikash maloroy
http://shawpnendu.blogspot.com
REGARDS
MCTS - Shawpnendu bikash maloroy
http://shawpnendu.blogspot.com
•
•
Join Date: Jun 2009
Posts: 412
Reputation:
Solved Threads: 81
Just change 'If rdr.HasRows' to 'If rdr.Read()'
Therefore your code should be as follows
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 Last edited by Ramesh S; Jul 8th, 2009 at 3:05 am.
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...
hope it helps...and if i'm wrong please let me know...
i guess you are missing toSting() function which is required...
in your code instead storing the string,you are storing the reader object...
ASP.NET Syntax (Toggle Plain Text)
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...
Last edited by peter_budo; Jul 10th, 2009 at 6:26 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
![]() |
Similar Threads
- ASP.Net perm full time programmer wanted (Web Development Job Offers)
- Experience ASP.net with C# developer needed!! (Web Development Job Offers)
- How to access session defined in asp(not .net) page in aspx.cs page (C#)
- ASP.Net / C# Web Developer (Web Development Job Offers)
- ASP.Net YAF Application Error (ASP.NET)
- ASP.Net Error with C# Coding (C#)
- "No Servers are available" Error with ASP.NET Webpage (Networking Hardware Configuration)
Other Threads in the ASP.NET Forum
- Previous Thread: How to check if page has been modified?
- Next Thread: creating data entry form
| Thread Tools | Search this Thread |
.net 2.0 3.5 activexcontrol advice ajax appliances asp asp.net bc30451 beginner bottomasp.net browser businesslogiclayer c# c#gridviewcolumn cac checkbox class compatible confirmationcodegeneration content contenttype countryselector courier css dataaccesslayer database datagrid datagridview datagridviewcheckbox datalist deployment development dgv dropdownmenu dynamic dynamically edit embeddingactivexcontrol fileuploader fill findcontrol flash flv forms gridview gudi homeedition iframe iis javascript jquery listbox menu mono mssql multistepregistration nameisnotdeclared news novell objects opera problem redirect registration relationaldatabases reportemail rotatepage security serializesmo.table sessionvariables silverlight smartcard smoobjects software sql sql-server ssl suse textbox tracking treeview unauthorized validatedate validation vb.net video videos virtualdirectory vista visual-studio visualstudio vs2008 web webapplications webarchitecture webdevelopemnt webdevelopment webprogramming





