Results 1 to 18 of 18

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

  1. #1

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

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

    Hi all,

    I decided to rewrite my login code because my last one would only find the first record and anything after that first record (additional records) werent even found but they were in the database (mssql express).

    I have a function that returns the connection string as follows:
    vb Code:
    1. Public Function ConString() As String
    2.         Return "Data Source=.\SQLExpress;Initial Catalog=CorpScore;User Id=MyUsername;Password=MyPassword;"
    3.     End Function
    I then have a public object for my connection and then I assign the connection string as follows:
    vb Code:
    1. Public m_objCon As New SqlClient.SqlConnection(ConString)
    When I enter in values in the username and password textboxes and click on the login button, it should do many checks and then log in if those checks are met for being valid. However, when i click on the login button, I get no errors and nothing happens at all. I even went to do a breakpoint and that isnt even executed. nothing happens at all. Please see code in the following three posts and advise if you see anything out of place. i am pretty new to .net so bear with me. the code is pretty long.....

  2. #2

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

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

    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 objAdminUserDa As New SqlClient.SqlDataAdapter, objRegularUserDa As New SqlClient.SqlDataAdapter
    5.         Dim blnAdminUser, blnRegularUser, blnAccountLocked As Boolean
    6.  
    7.         'set up new sql commands and assign the sql query
    8.         Dim objAdminUserCmd As New SqlClient.SqlCommand("SELECT * " & _
    9.                                                         "FROM Users " & _
    10.                                                         "WHERE IsAdmin = 1", m_objCon)
    11.  
    12.         Dim objRegularUserCmd As New SqlClient.SqlCommand("SELECT * " & _
    13.                                                           "FROM Users " & _
    14.                                                           "WHERE IsAdmin = 0", m_objCon)
    15.  
    16.         Try
    17.             'open the connection
    18.             m_objCon.Open()
    19.  
    20.             'clear the data sets and then fill the data adapters with the data sets
    21.             objAdminUserDs.Clear()
    22.             objAdminUserDa.Fill(objAdminUserDs)
    23.  
    24.             objRegularUserDs.Clear()
    25.             objRegularUserDa.Fill(objRegularUserDs)
    26.  
    27.             'if there are more than zero rows in the admin dataset then
    28.             If objAdminUserDs.Tables(0).Rows.Count > 0 Then
    29.                 'set the boolean
    30.                 blnAdminUser = True
    31.                 blnRegularUser = False
    32.  
    33.                 'get the information for the administrator user
    34.                 With objAdminUserDs.Tables(0).Rows(0)
    35.                     m_strUsername = .Item("Username").ToString
    36.                     m_strPassword = .Item("Password").ToString
    37.                     blnAccountLocked = CType(.Item("AccountLocked"), Boolean)
    38.                     m_dteLastPasswordChange = .Item("LastPasswordChange")
    39.                 End With
    40.                 'if there are more than zero rows in the regular users data set then
    41.             ElseIf objRegularUserDs.Tables(0).Rows.Count > 0 Then
    42.                 'set the boolean flag
    43.                 blnAdminUser = False
    44.                 blnRegularUser = True
    45.  
    46.                 'get the information for the regular user
    47.                 With objRegularUserDs.Tables(0).Rows(0)
    48.                     m_strUsername = .Item("Username").ToString
    49.                     m_strPassword = .Item("Password").ToString
    50.                     blnAccountLocked = CType(.Item("AccountLocked"), Boolean)
    51.                     m_dteLastPasswordChange = .Item("LastPasswordChange")
    52.                 End With
    53.             Else 'no user found
    54.                 'set the boolean flags to false and then show the messagebox
    55.                 blnAdminUser = False
    56.                 blnRegularUser = False
    57.  
    58.                 If MessageBox.Show("Username and / or password mismatch." & vbNewLine & _
    59.                                    "Please try again or contact support." & vbNewLine, _
    60.                                    "Logon Mismatch", _
    61.                                    MessageBoxButtons.OK, _
    62.                                    MessageBoxIcon.Exclamation, _
    63.                                    MessageBoxDefaultButton.Button1, _
    64.                                    MessageBoxOptions.ServiceNotification, _
    65.                                    False) = Windows.Forms.DialogResult.OK Then
    66.  
    67.                     'when the ok button is clicked, reset the login form and
    68.                     'reset the cursor focus
    69.                     ResetScreen(Me)
    70.  
    71.                     'put the cursor back into the username field
    72.                     txtUsername.Focus()
    73.                 End If
    74.             End If

  3. #3

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

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

    vb Code:
    1. 'do something with any returned records
    2.             'first calculate how many days old the password is and then assign
    3.             'it to TimeSpan to get the difference in days
    4.             dteChangePassword = dteTodaysDate - m_dteLastPasswordChange
    5.  
    6.             'if the password is equal to more than 30 days old and the account isnt
    7.             'in locked status then show the change password form.  this will happen
    8.             'every 30 days to increase security
    9.             If dteChangePassword.Days.ToString > 30 _
    10.             And Not blnAccountLocked _
    11.             And txtUsername.Text.Trim = m_strUsername _
    12.             And txtPassword.Text.Trim = m_strPassword Then
    13.                 Dim fChangePassword As New frmChangePassword
    14.  
    15.                 With fChangePassword
    16.                     'set the MDI parent as frmMain
    17.                     .MdiParent = Me.MdiParent
    18.                     'center the form
    19.                     .Location = New Point((.MdiParent.Width - .Width) / 2, (.MdiParent.Height - .Height) / 2)
    20.                     'now show the form
    21.                     .Show()
    22.                 End With
    23.             Else 'password doesnt need to be changed, proceed....
    24.                 'lets check to see if the user is a regular user and that the account isnt locked
    25.                 If blnRegularUser _
    26.                 And Not blnAccountLocked _
    27.                 And txtUsername.Text.Trim = m_strUsername _
    28.                 And txtPassword.Text.Trim = m_strPassword Then
    29.                     'let the user in
    30.                     LetUserIn()
    31.                     'lets now check to see if the user is a regular user and the account is locked
    32.                     'if the account is locked, advise the end user
    33.                 ElseIf blnRegularUser _
    34.                 And blnAccountLocked _
    35.                 And txtUsername.Text.Trim = m_strUsername _
    36.                 And txtPassword.Text.Trim = m_strPassword Then
    37.                     If MessageBox.Show("We cannot log you into " & AppName() & "." & vbNewLine & vbNewLine & _
    38.                                        "Reason: Account is in locked status." & vbNewLine & _
    39.                                        "Solution: Contact an administrator.", _
    40.                                        "Account Locked", _
    41.                                        MessageBoxButtons.OK, _
    42.                                        MessageBoxIcon.Exclamation, _
    43.                                        MessageBoxDefaultButton.Button1, _
    44.                                        MessageBoxOptions.ServiceNotification, _
    45.                                        False) = Windows.Forms.DialogResult.OK Then
    46.  
    47.                         'reset the form
    48.                         ResetScreen(Me)
    49.  
    50.                         'reset the cursor focus
    51.                         txtUsername.Focus()
    52.                     End If
    53.                     'if the account for the user isnt locked but the username doesnt match
    54.                 ElseIf blnRegularUser _
    55.                 And Not blnAccountLocked _
    56.                 And Not txtUsername.Text.Trim = m_strUsername _
    57.                 And txtPassword.Text.Trim = m_strPassword Then
    58.                     If MessageBox.Show("We cannot log you into " & AppName() & "." & vbNewLine & vbNewLine & _
    59.                                        "Reason: Username mismatch." & vbNewLine & _
    60.                                        "Solution: Try again.", _
    61.                                        "Username Mismatch", _
    62.                                        MessageBoxButtons.OK, _
    63.                                        MessageBoxIcon.Exclamation, _
    64.                                        MessageBoxDefaultButton.Button1, _
    65.                                        MessageBoxOptions.ServiceNotification, _
    66.                                        False) = Windows.Forms.DialogResult.OK Then
    67.  
    68.                         'reset the form
    69.                         ResetScreen(Me)
    70.  
    71.                         'reset the cursor focus
    72.                         txtUsername.Focus()
    73.                     End If
    74.                     'if the account for the user isnt locked but the password doesnt match
    75.                 ElseIf blnRegularUser _
    76.                 And Not blnAccountLocked _
    77.                 And txtUsername.Text.Trim = m_strUsername _
    78.                 And Not txtUsername.Text.Trim = m_strPassword Then
    79.                     If MessageBox.Show("We cannot log you into " & AppName() & "." & vbNewLine & vbNewLine & _
    80.                                        "Reason: Password mismatch." & vbNewLine & _
    81.                                        "Solution: Try again.", _
    82.                                        "Password Mismatch", _
    83.                                        MessageBoxButtons.OK, _
    84.                                        MessageBoxIcon.Exclamation, _
    85.                                        MessageBoxDefaultButton.Button1, _
    86.                                        MessageBoxOptions.ServiceNotification, _
    87.                                        False) = Windows.Forms.DialogResult.OK Then
    88.  
    89.                         'reset the form
    90.                         ResetScreen(Me)
    91.  
    92.                         'reset the cursor focus
    93.                         txtUsername.Focus()
    94.                     End If
    95.                     'now lets check to see if the user is an administrator and if the account isnt locked

  4. #4

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

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

    last part
    vb Code:
    1. ElseIf blnAdminUser _
    2.                 And Not blnAccountLocked _
    3.                 And txtUsername.Text.Trim = m_strUsername _
    4.                 And txtPassword.Text.Trim = m_strPassword Then
    5.                     'let the user in
    6.                     LetUserIn()
    7.  
    8.                     'now lets check to see if the user is an administrator and if the account is locked
    9.                     'then ask the administrator if they want to reset the accounts locked status.  this
    10.                     'is a bad thing if there is only one admin account and the account is locked because  
    11.                     'only admins can reset the locked status
    12.                 ElseIf blnAdminUser _
    13.                 And blnAccountLocked _
    14.                 And txtUsername.Text.Trim = m_strUsername _
    15.                 And txtPassword.Text.Trim = m_strPassword Then
    16.                     If MessageBox.Show("We cannot log you into " & AppName() & "." & vbNewLine & vbNewLine & _
    17.                                        "Reason: Account is in locked status." & vbNewLine & _
    18.                                        "Solution: Account reset." & vbNewLine & vbNewLine & _
    19.                                        "Would you like to reset your account?", _
    20.                                        "Account Locked", _
    21.                                        MessageBoxButtons.YesNo, _
    22.                                        MessageBoxIcon.Question, _
    23.                                        MessageBoxDefaultButton.Button1, _
    24.                                        MessageBoxOptions.ServiceNotification, _
    25.                                        False) = Windows.Forms.DialogResult.Yes Then
    26.  
    27.                         'reset the administrators account
    28.                         'first select the administrator
    29.                         Dim objSelectAdminAccountCmd As New SqlClient.SqlCommand("SELECT Username, AccountLocked " & _
    30.                                                                                  "FROM Users " & _
    31.                                                                                  "WHERE Username = '" & m_strUsername & "' " & _
    32.                                                                                  "AND IsAdmin = 1 " & _
    33.                                                                                  "AND AccountLocked = 1", m_objCon)
    34.  
    35.                         'execute the command
    36.                         objSelectAdminAccountCmd.ExecuteNonQuery()
    37.  
    38.                         'now reset the account locked status from 1 to 0
    39.                         Dim objResetAdminAccountCmd As New SqlClient.SqlCommand("UPDATE Users " & _
    40.                                                                                 "SET AccountLocked = 0 " & _
    41.                                                                                 "WHERE Username = '" & m_strUsername & "' " & _
    42.                                                                                 "AND IsAdmin = 1", m_objCon)
    43.  
    44.                         'execute the command
    45.                         objResetAdminAccountCmd.ExecuteNonQuery()
    46.                     End If
    47.                     'now check to see if the user is an admin, the account isnt locked but the username doesnt match
    48.                 ElseIf blnAdminUser _
    49.                 And Not blnAccountLocked _
    50.                 And Not txtUsername.Text.Trim = m_strUsername _
    51.                 And txtPassword.Text.Trim = m_strPassword Then
    52.                     If MessageBox.Show("We cannot log you into " & AppName() & "." & vbNewLine & vbNewLine & _
    53.                                        "Reason: Username mismatch." & vbNewLine & _
    54.                                        "Solution: Try again.", _
    55.                                        "Username Mismatch", _
    56.                                        MessageBoxButtons.OK, _
    57.                                        MessageBoxIcon.Exclamation, _
    58.                                        MessageBoxDefaultButton.Button1, _
    59.                                        MessageBoxOptions.ServiceNotification, _
    60.                                        False) = Windows.Forms.DialogResult.OK Then
    61.  
    62.                         'reset the form
    63.                         ResetScreen(Me)
    64.  
    65.                         'reset the cursor focus
    66.                         txtUsername.Focus()
    67.                     End If
    68.                     'now lets finally check to see if the user is an admin, the account isnt locked but the
    69.                     'password doesnt match
    70.                 ElseIf blnAdminUser _
    71.                 And Not blnAccountLocked _
    72.                 And txtUsername.Text.Trim = m_strUsername _
    73.                 And Not txtPassword.Text.Trim = m_strPassword Then
    74.                     If MessageBox.Show("We cannot log you into " & AppName() & "." & vbNewLine & vbNewLine & _
    75.                                        "Reason: Password mismatch." & vbNewLine & _
    76.                                        "Solution: Try again.", _
    77.                                        "Password Mismatch", _
    78.                                        MessageBoxButtons.OK, _
    79.                                        MessageBoxIcon.Exclamation, _
    80.                                        MessageBoxDefaultButton.Button1, _
    81.                                        MessageBoxOptions.ServiceNotification, _
    82.                                        False) = Windows.Forms.DialogResult.OK Then
    83.  
    84.                         'reset the form
    85.                         ResetScreen(Me)
    86.  
    87.                         'reset the cursor focus
    88.                         txtUsername.Focus()
    89.                     End If
    90.                 End If
    91.             End If
    92.         Catch ex As Exception
    93.  
    94.         Finally
    95.             'now destroy all the data sets and data adapaters
    96.             objAdminUserDs.Dispose()
    97.             objRegularUserDs.Dispose()
    98.             objAdminUserDa.Dispose()
    99.             objRegularUserDa.Dispose()
    100.  
    101.             'if the connection to the database is open, close it
    102.             If m_objCon.State = ConnectionState.Open Then
    103.                 m_objCon.Close()
    104.             End If
    105.         End Try
    106.     End Sub

  5. #5

    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.

  6. #6

    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

  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)

    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.

  8. #8

    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)

  9. #9
    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.

  10. #10

    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

  11. #11

    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)

  12. #12
    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())

  13. #13

    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())

  14. #14

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

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

    now i changed my code and it gets the 2nd user but not the first. jeez!!!!!!!!!!
    vb Code:
    1. For Each objRows As DataRow In objUsersDt.Rows
    2.                 'get the information for the user
    3.                 With objRows
    4.                     m_strUsername = .Item("Username").ToString
    5.                     m_strPassword = .Item("Password").ToString
    6.                     blnAccountLocked = CType(.Item("AccountLocked"), Boolean)
    7.                     m_dteLastPasswordChange = .Item("LastPasswordChange")
    8.                     blnCheckForAdmin = CType(.Item("IsAdmin"), Boolean)
    9.                 End With
    10.             Next objRows

  15. #15
    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
    when the messagebox comes up, it has the number 2 in it.
    That means there are two records there. That's what you want correct?

    A DataSet is just a collection of DataTables. Check them both out on MSDN.

    I imagine that you are getting the second one because you are overwriting the first when you loop through all of the rows in that table.

    You need to step through this code and see what is going on. Slap a breakpoint on the first line in your block of code and actually walk through it and watch all of your variables and actually see how and when they change.

  16. #16
    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)

    Ok. So, there is probably a better way to do this, but using something like your code, this works for me using the NorthWind database:
    Code:
    Public Class Form1
    
        Private _productName As String
        Private _productID As Integer
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Nwind.mdb;")
            Dim SQLString1 As String = _
                "SELECT ProductID, ProductName " & _
                "FROM Products " & _
                "WHERE ProductID = -1"
            Dim SQLString2 As String = _
                "SELECT ProductID, ProductName " & _
                "FROM Products " & _
                "WHERE ProductID = 2"
            Dim da1 As New OleDbDataAdapter(SQLString1, conn)
            Dim da2 As New OleDbDataAdapter(SQLString2, conn)
    
            Dim dt1 As New DataTable()
            Dim dt2 As New DataTable()
            da1.Fill(dt1)
            da2.Fill(dt2)
    
            If dt1.Rows.Count > dt2.Rows.Count Then
                _productID = CInt(dt1.Rows(0).Item("ProductID"))
                _productName = dt1.Rows(0).Item("ProductName").ToString()
            Else
                _productID = CInt(dt2.Rows(0).Item("ProductID"))
                _productName = dt2.Rows(0).Item("ProductName").ToString()
            End If
    
            MessageBox.Show( _
                _productID & _
                Environment.NewLine & _
                _productName)
    
        End Sub
    
    End Class

  17. #17

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

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

    thanks for that. i think i am making some headway here but gonna test further to make sure.

    when an admin user logs into the system, they have complete access to everything. on form load, so far I have three menus that are disabled but when the admin user logs in, they need to be enabled. so in my frmLogin form, I have used DirectCast() but when I go to login as an admin, i get the following error in the screen shot.

    i am not sure how to access controls on another form and had asked this question in the forum last week (didnt get a response though) but is this the way you access controls on another form or is there another way?

    Thanks in advance and for your patience so far.
    Attached Images Attached Images  

  18. #18

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

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

    seemed to have fixed the problem by doing"
    vb Code:
    1. 'enable the menus because admins have access to those
    2.                 With DirectCast(Me.MdiParent, frmMain)
    3.                     .mnuUsers.Enabled = True
    4.                     .mnuPrint.Enabled = True
    5.                     .mnuSettings.Enabled = True
    6.                 End With
    7.  
    8.                 'let the user in
    9.                 LetUserIn()

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