Results 1 to 18 of 18

Thread: [RESOLVED] [2005] Login form code (no errors, does nothing)

Hybrid View

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: [2005] Login form code (no errors, does nothing)

    i took out the try/catch block because that wasnt showing me errors and i think ive figured it out. time for more testing and will be back.

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: [2005] Login form code (no errors, does nothing)

    ok, i am getting very frustrated with .net right about now. no matter how i code this damned thing, it never sees past the first record!!!!!!

    almost to the point of quitting this altogether. please advise what i am doing wrong. both the data sets are being populated with the SAME record regardless!!!!

    complete code in txt file attachment. thanks in advance for any help.
    vb Code:
    1. Private Sub cmdLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLogin.Click
    2.         'declare some datasets, data adapters and boolean flags
    3.         Dim objAdminUserDs As New DataSet, objRegularUserDs As New DataSet
    4.         Dim blnAdminUser, blnRegularUser, blnAccountLocked As Boolean
    5.  
    6.         'set up new sql commands and assign the sql query
    7.         Dim strAdminUserSQL As String = "SELECT * " & _
    8.                                         "FROM Users " & _
    9.                                         "WHERE IsAdmin = '1'"
    10.  
    11.         Dim strRegularUserSQL As String = "SELECT * " & _
    12.                                           "FROM Users " & _
    13.                                           "WHERE IsAdmin = '0'"
    14.  
    15.         Dim objAdminUserDa As New SqlClient.SqlDataAdapter(strAdminUserSQL, m_objCon)
    16.         Dim objRegularUserDa As New SqlClient.SqlDataAdapter(strRegularUserSQL, m_objCon)
    17.  
    18.         'Try
    19.  
    20.         'open the connection if its closed
    21.         If m_objCon.State = ConnectionState.Closed Then
    22.             m_objCon.Open()
    23.         End If
    24.  
    25.         'clear the data sets and then fill the data adapters with the data sets
    26.         objAdminUserDs.Clear()
    27.         objAdminUserDa.Fill(objAdminUserDs)
    28.  
    29.         objRegularUserDs.Clear()
    30.         objRegularUserDa.Fill(objRegularUserDs)
    31.  
    32.         'if there are more than zero rows in the admin dataset then
    33.         If objAdminUserDs.Tables(0).Rows.Count > 0 Then
    34.             'set the boolean
    35.             blnAdminUser = True
    36.             blnRegularUser = False
    37.  
    38.             'get the information for the administrator user
    39.             With objAdminUserDs.Tables(0).Rows(0)
    40.                 m_strUsername = .Item("Username").ToString
    41.                 m_strPassword = .Item("Password").ToString
    42.                 blnAccountLocked = CType(.Item("AccountLocked"), Boolean)
    43.                 m_dteLastPasswordChange = .Item("LastPasswordChange")
    44.             End With
    45.             'if there are more than zero rows in the regular users data set then
    46.         ElseIf objRegularUserDs.Tables(0).Rows.Count > 0 Then
    47.             'set the boolean flag
    48.             blnAdminUser = False
    49.             blnRegularUser = True
    50.  
    51.             'get the information for the regular user
    52.             With objRegularUserDs.Tables(0).Rows(0)
    53.                 m_strUsername = .Item("Username").ToString
    54.                 m_strPassword = .Item("Password").ToString
    55.                 blnAccountLocked = CType(.Item("AccountLocked"), Boolean)
    56.                 m_dteLastPasswordChange = .Item("LastPasswordChange")
    57.             End With
    58.         End If
    Attached Files Attached Files

  3. #3
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: [2005] Login form code (no errors, does nothing)

    Quote Originally Posted by BrailleSchool
    i took out the try/catch block because that wasnt showing me errors and i think ive figured it out. time for more testing and will be back.
    In fact, that is the first thing that catches my eye in the last bit of code. The Try...Catch block is there so if you do experience an error in your code, you can respond to it somehow. Even it is only to show a MessageBox with the error message, you should really put some code in your Catch block. Otherwise, as you've discovered, you won't get any information at all.

    Don't remove the Try...Catch block. Just do something with the error when you catch it.

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: [2005] Login form code (no errors, does nothing)

    Quote Originally Posted by nmadd
    In fact, that is the first thing that catches my eye in the last bit of code. The Try...Catch block is there so if you do experience an error in your code, you can respond to it somehow. Even it is only to show a MessageBox with the error message, you should really put some code in your Catch block. Otherwise, as you've discovered, you won't get any information at all.

    Don't remove the Try...Catch block. Just do something with the error when you catch it.
    i have totally rewritten this code from scratch 3 times now and doesnt matter how i do it, it only sees the first record and no other records. i currently have two users in the db. the first one can login without issue and the second one "cant be found" when in fact everything is typed in right. argh! (post #6 has additional info)

  5. #5
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: [2005] Login form code (no errors, does nothing)

    1) So you said you removed the Try...Catch block so you could see the errors. What where they?
    2) Is your IsAdmin field a number field? There should not be single quotes around the 1 and 0 if that is so.

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: [2005] Login form code (no errors, does nothing)

    Quote Originally Posted by nmadd
    1) So you said you removed the Try...Catch block so you could see the errors. What where they?
    2) Is your IsAdmin field a number field? There should not be single quotes around the 1 and 0 if that is so.
    IsAdmin is actually a varchar(5)

  7. #7
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: [2005] Login form code (no errors, does nothing)

    So you only get one record back when you are certain there is more than one record in your database table?

    How many rows does this return?
    Code:
            Dim strUsersSQL As String = "SELECT * " & _
                                        "FROM Users"
            Dim objUsersDa As New SqlClient.SqlDataAdapter(strUsersSQL, m_objCon)
            Dim dt As New DataTable()
    
            objUsersDa.Fill(dt)
            MessageBox.Show(dt.Rows.Count.ToString())

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: [2005] Login form code (no errors, does nothing)

    when the messagebox comes up, it has the number 2 in it.
    i have gotten rid of the dataset and gone to datatable instead. whats the difference between the dataset and datatable?

    still no change. first user has no issues. 2nd one cant be found. ugh
    Quote Originally Posted by nmadd
    So you only get one record back when you are certain there is more than one record in your database table?

    How many rows does this return?
    Code:
            Dim strUsersSQL As String = "SELECT * " & _
                                        "FROM Users"
            Dim objUsersDa As New SqlClient.SqlDataAdapter(strUsersSQL, m_objCon)
            Dim dt As New DataTable()
    
            objUsersDa.Fill(dt)
            MessageBox.Show(dt.Rows.Count.ToString())

  9. #9

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: [2005] Login form code (no errors, does nothing)

    i even changed it to the following an no change. can only see the first user and the dataset isnt updated with any other records. ugh. i am totally lost with .net
    vb Code:
    1. 'declare some datasets, data adapters and boolean flags
    2.         Dim objUsersDs As New DataSet
    3.         Dim blnAdminUser, blnRegularUser, blnCheckForAdmin, blnAccountLocked As Boolean
    4.  
    5.         'set up new sql commands and assign the sql query
    6.         Dim strUsersSQL As String = "SELECT * " & _
    7.                                     "FROM Users"
    8.  
    9.         Dim objUsersDa As New SqlClient.SqlDataAdapter(strUsersSQL, m_objCon)
    10.  
    11.         'Try
    12.  
    13.         'open the connection if its closed
    14.         If m_objCon.State = ConnectionState.Closed Then
    15.             m_objCon.Open()
    16.         End If
    17.  
    18.         'clear the data set and then fill the data adapter with the data set
    19.         objUsersDs.Clear()
    20.         objUsersDa.Fill(objUsersDs)
    21.  
    22.         'if there are more than zero rows in the admin dataset then
    23.         If objUsersDs.Tables(0).Rows.Count > 0 Then
    24.             'get the information for the administrator user
    25.             With objUsersDs.Tables(0).Rows(0)
    26.                 m_strUsername = .Item("Username").ToString
    27.                 m_strPassword = .Item("Password").ToString
    28.                 blnAccountLocked = CType(.Item("AccountLocked"), Boolean)
    29.                 m_dteLastPasswordChange = .Item("LastPasswordChange")
    30.                 blnCheckForAdmin = CType(.Item("IsAdmin"), Boolean)
    31.             End With
    32.  
    33.             'set the boolean flag
    34.             If blnCheckForAdmin Then
    35.                 blnAdminUser = True
    36.                 blnRegularUser = False
    37.             Else
    38.                 blnAdminUser = False
    39.                 blnRegularUser = True
    40.             End If
    41.         End If

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width