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:
Private Sub cmdLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLogin.Click
'declare some datasets, data adapters and boolean flags
Dim objAdminUserDs As New DataSet, objRegularUserDs As New DataSet
Dim blnAdminUser, blnRegularUser, blnAccountLocked As Boolean
'set up new sql commands and assign the sql query
Dim strAdminUserSQL As String = "SELECT * " & _
"FROM Users " & _
"WHERE IsAdmin = '1'"
Dim strRegularUserSQL As String = "SELECT * " & _
"FROM Users " & _
"WHERE IsAdmin = '0'"
Dim objAdminUserDa As New SqlClient.SqlDataAdapter(strAdminUserSQL, m_objCon)
Dim objRegularUserDa As New SqlClient.SqlDataAdapter(strRegularUserSQL, m_objCon)
'Try
'open the connection if its closed
If m_objCon.State = ConnectionState.Closed Then
m_objCon.Open()
End If
'clear the data sets and then fill the data adapters with the data sets
objAdminUserDs.Clear()
objAdminUserDa.Fill(objAdminUserDs)
objRegularUserDs.Clear()
objRegularUserDa.Fill(objRegularUserDs)
'if there are more than zero rows in the admin dataset then
Re: [2005] Login form code (no errors, does nothing)
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.
Re: [2005] Login form code (no errors, does nothing)
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)
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.
Re: [2005] Login form code (no errors, does nothing)
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.
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())
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
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())
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:
'declare some datasets, data adapters and boolean flags
Dim objUsersDs As New DataSet
Dim blnAdminUser, blnRegularUser, blnCheckForAdmin, blnAccountLocked As Boolean
'set up new sql commands and assign the sql query
Dim strUsersSQL As String = "SELECT * " & _
"FROM Users"
Dim objUsersDa As New SqlClient.SqlDataAdapter(strUsersSQL, m_objCon)
'Try
'open the connection if its closed
If m_objCon.State = ConnectionState.Closed Then
m_objCon.Open()
End If
'clear the data set and then fill the data adapter with the data set
objUsersDs.Clear()
objUsersDa.Fill(objUsersDs)
'if there are more than zero rows in the admin dataset then