VS 2010 - VB Login Query returning one row all the time

SQLConPPI.SQLDSPPI.Tables.Count  is always returning one row, so I cannot see an invalid login - someone said I should be querying the data fill - I just dont know what to do?!!?

      Dim strLogin As New System.Text.StringBuilder
            strLogin.Append("Select * from [PD_MA_USERS] where username = '")
            strLogin.Append(Me.txtUserName.Text)
            strLogin.Append("' and password = '")
            strLogin.Append(Me.txtPassword.Text)
            strLogin.Append("'")
            MessageBox.Show(strLogin.ToString())
 
            'strLogin.Append(strLogin.ToString())
            If SQLConPPI.HasConnection = True Then
                SQLConPPI.PersonelForAssignment(strLogin.ToString)
                MsgBox(Str(SQLConPPI.SQLDSPPI.Tables.Count))
                If SQLConPPI.SQLDSPPI.Tables.Count > 0 Then
                    Dim Open_Main_PD As Form = Main_PD
 
                    Me.Visible = False
                    Open_Main_PD.ShowDialog()
                    Exit Sub
                Else
                    MessageBox.Show("Login credentials incorrect")
                End If
            End If

Open in new window

ralphp1355Asked:
Who is Participating?
 
chaauCommented:
First of all, your query is prone to the SQL injection.
If I type this string as the user name and type 1 as a password your query will let me in:
a' or 1=1;--

Open in new window

(you can test once you fix your problems)

Now, to your problem. The SQLConPPI.SQLDSPPI.Tables is most likely a collection of tables. You need to check the SQLConPPI.SQLDSPPI.Tables(0), as it is most likely will be the one that is filled with data. I do not know the code inside your PersonelForAssignment function, I just assume it. So, you need to test like this:
If SQLConPPI.SQLDSPPI.Tables.Count > 0 AndAlso SQLConPPI.SQLDSPPI.Tables(0).Rows.Count > 0 Then

Open in new window

0
 
ralphp1355Author Commented:
Great thank you
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.