Question How to Get all users name in a table

jhekz41

New member
Joined
Sep 30, 2012
Messages
3
Programming Experience
Beginner
I want to filter the users input if it is already in the users database

here's my code: Problem is only one users has been detected. : I do not know how to get users database into one variable..

Me.user = txtbox.text
Try
cnn.Open()
Dim stm As String = "Select mgt_user from tbl_management"


Dim cmd As MySqlClient.MySqlCommand = New MySqlClient.MySqlCommand(stm, cnn)
Dim reader As MySqlClient.MySqlDataReader = cmd.ExecuteReader()


reader.Read()




Mgtuser = reader.GetString("mgt_user")


reader.Close()




If Me.user = Mgtuser Then
MsgBox("the name is already exists")
End If
If Me.user <> Mgtuser Then
MsgBox("ndi xa equal")
End If








Catch ex As MySqlClient.MySqlException
MsgBox("INVALID ACCOUNT", MessageBoxIcon.Error, "CSM")
Finally
cnn.Close()
End Try



THANKS IN ADVANCE :D
 
You're only calling Read once so you're only reading one record. If you want to read every record in the result set then you have to call Read with a loop until it returns False.

You don't need to get every record though. In fact, you don't need to read any records. It appears that all you want to do is determine whether a particular value already exists in the database. In that case all you need to get is a count of matching records, e.g.
VB.NET:
SELECT COUNT(*) FROM tbl_management WHERE mgt_user = @mgt_user
You can then call ExecuteScalar on your command and it will return 1 if there's a match or 0 if there isn't.
 
You're only calling Read once so you're only reading one record. If you want to read every record in the result set then you have to call Read with a loop until it returns False.

You don't need to get every record though. In fact, you don't need to read any records. It appears that all you want to do is determine whether a particular value already exists in the database. In that case all you need to get is a count of matching records, e.g.
VB.NET:
SELECT COUNT(*) FROM tbl_management WHERE mgt_user = @mgt_user
You can then call ExecuteScalar on your command and it will return 1 if there's a match or 0 if there isn't.




>>>>>SIR... MORE THANKS TO YOU... :D even you did not gave me the codes.. You gave me the idea.. AND Its done... Thanks again.
 
Back
Top