| | |
login code with roles
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2009
Posts: 36
Reputation:
Solved Threads: 0
hi there,
i am coming up with a login page and i am having problem with the codes while i run the program. The error says, Invalid attempt to read when no data is present.' This errors occurs when i type 'gobi' as the delivery boy.
The error says 'FirstName'. when i enter '123456' as the customer.
Else
ddltype.SelectedValue = "DeliveryBoy"
Session("ses_uname") = rdr("FirstName") + " " + rdr("LastName") Session("ses_uid") = rdr("staffid")
Session("ses_utype") = rdr("Designation")
Response.Redirect("Direct.aspx")
i am coming up with a login page and i am having problem with the codes while i run the program. The error says, Invalid attempt to read when no data is present.' This errors occurs when i type 'gobi' as the delivery boy.
The error says 'FirstName'. when i enter '123456' as the customer.
Else
ddltype.SelectedValue = "DeliveryBoy"
Session("ses_uname") = rdr("FirstName") + " " + rdr("LastName") Session("ses_uid") = rdr("staffid")
Session("ses_utype") = rdr("Designation")
Response.Redirect("Direct.aspx")
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.Read() Then
If ddltype.SelectedValue = "Manager" Then
Session("ses_dname") = rdr("FirstName") + " " + rdr("LastName")
Session("ses_uid") = rdr("StaffID")
Response.Redirect("ManagerDirect.aspx")
ElseIf rdr.Read() Then
If ddltype.SelectedValue = "Customer" Then
Session("ses_dname") = rdr("CusFname") + " " + rdr("CusLName")
Session("ses_uid") = rdr("cusid")
'Session("ses_utype") = rdr("Designation")
Response.Redirect("Domestic.aspx")
End If
'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("Direct.aspx")
End If
End If
End Sub
End Class Last edited by chrispaul8676; Jul 12th, 2009 at 5:52 am. Reason: not proper
chrispaul8676,
This method must be issued once if result is a single row.
This method must be issued once if result is a single row.
ASP.NET Syntax (Toggle Plain Text)
rdr.Read()
Failure is not fatal, but failure to change might be. - John Wooden
VB.NET - Use & sign to concat strings.
VB.NET Syntax (Toggle Plain Text)
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.Read() Then If ddltype.SelectedValue = "Manager" Then Session("ses_dname") = rdr("FirstName") & " " & rdr("LastName") Session("ses_uid") = rdr("StaffID") Response.Redirect("ManagerDirect.aspx") End If If ddltype.SelectedValue = "Customer" Then Session("ses_dname") = rdr("CusFname") & " " & rdr("CusLName") Session("ses_uid") = rdr("cusid") Response.Redirect("Domestic.aspx") End IF If ddltype.SelectedValue = "DeliveryBoy" Session("ses_uname") = rdr("FirstName") & " " & rdr("LastName") Session("ses_uid") = rdr("staffid") Session("ses_utype") = rdr("Designation") Response.Redirect("Direct.aspx") End If End If End Sub End Class
Failure is not fatal, but failure to change might be. - John Wooden
![]() |
Similar Threads
- problem in the login code (ASP.NET)
- login code (Visual Basic 4 / 5 / 6)
- i need login code in C# (C#)
- login code in C#(its urgent) (C#)
Other Threads in the ASP.NET Forum
- Previous Thread: Send Email from SQL server
- Next Thread: FileUpload automatically upload after set filepath
| Thread Tools | Search this Thread |
.net 3.5 ajax alltypeofvideos appliances asp asp.net bc30451 beginner box browser businesslogiclayer button c# cac checkbox class commonfunctions control countryselector dataaccesslayer database datagrid datagridview datagridviewcheckbox datalist deployment development dgv dialog dropdownlist dropdownmenu dynamic dynamically edit embeddingactivexcontrol expose fileuploader fill findcontrol flash formatdecimal formview gridview gudi iis javascript list listbox login microsoft mouse mssql nameisnotdeclared news novell numerical opera panelmasterpagebuttoncontrols problem radio redirect registration relationaldatabases reportemail save schoolproject search security sessionvariables silverlight smartcard smoobjects software sql sql-server sqlserver2005 ssl suse textbox tracking treeview unauthorized validatedate validation vb.net video videos vista visualstudio vs2008 web webapplications webdevelopemnt webdevelopment webprogramming webservice wizard xsl youareanotmemberofthedebuggerusers






