login code with roles

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2009
Posts: 36
Reputation: chrispaul8676 is an unknown quantity at this point 
Solved Threads: 0
chrispaul8676 chrispaul8676 is offline Offline
Light Poster

login code with roles

 
0
  #1
Jul 12th, 2009
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")

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
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,582
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 457
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: login code with roles

 
0
  #2
Jul 12th, 2009
chrispaul8676,
This method must be issued once if result is a single row.
  1. rdr.Read()
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 36
Reputation: chrispaul8676 is an unknown quantity at this point 
Solved Threads: 0
chrispaul8676 chrispaul8676 is offline Offline
Light Poster

Re: login code with roles

 
0
  #3
Jul 13th, 2009
sorry, but i don't understand this..please assist me.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,582
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 457
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: login code with roles

 
0
  #4
Jul 13th, 2009
VB.NET - Use & sign to concat strings.

  1. Imports System.Data.Sql
  2. Imports System.Data.SqlClient
  3. Imports System.Web
  4. Partial Class _Default
  5. Inherits System.Web.UI.Page
  6. Dim str As String = ConfigurationManager.ConnectionStrings("CourierSystemConnectionString").ConnectionString
  7. Dim con As SqlConnection
  8. Dim cmd As SqlCommand
  9. Dim rdr As SqlDataReader
  10. Dim sql As String
  11. Dim t As String
  12.  
  13. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  14. End Sub
  15. Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnlogin.Click
  16. con = New SqlConnection(str)
  17. con.Open()
  18. Dim type As String
  19. type = ddltype.SelectedValue
  20. If type = "Customer" Then
  21. sql = "select * from CusRegis_Table where CusID='" & tuname.Text & "' and password2='" & tupass.Text & "'"
  22.  
  23. Else
  24. sql = "select * from StaffRegis_Table where StaffID='" &
  25. tuname.Text & "' and Password='" & tupass.Text & "'"
  26. End If
  27.  
  28. cmd = New SqlCommand(sql, con)
  29. rdr = cmd.ExecuteReader
  30.  
  31. If rdr.Read() Then
  32. If ddltype.SelectedValue = "Manager" Then
  33. Session("ses_dname") = rdr("FirstName") & " "
  34. & rdr("LastName")
  35. Session("ses_uid") = rdr("StaffID")
  36. Response.Redirect("ManagerDirect.aspx")
  37. End If
  38. If ddltype.SelectedValue = "Customer" Then
  39. Session("ses_dname") = rdr("CusFname") & " "
  40. & rdr("CusLName")
  41. Session("ses_uid") = rdr("cusid")
  42. Response.Redirect("Domestic.aspx")
  43. End IF
  44. If ddltype.SelectedValue = "DeliveryBoy"
  45. Session("ses_uname") = rdr("FirstName") & " "
  46. & rdr("LastName")
  47. Session("ses_uid") = rdr("staffid")
  48. Session("ses_utype") = rdr("Designation")
  49. Response.Redirect("Direct.aspx")
  50. End If
  51. End If
  52.  
  53. End Sub
  54. End Class
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the ASP.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC