0

Public Sub SearchUser()
Try

conn = New MySqlConnection()
conn.ConnectionString = "server=localhost; user id=root; database=eps"
conn.Open()

sqlquery = "SELECT username FROM pass WHERE username = '" & cmbUserName.Text & "'"
Dim myCommand As New MySqlCommand()
myCommand.Connection = conn
myCommand.CommandText = sqlquery

'start query
myAdapter.SelectCommand = myCommand

Dim myData As MySqlDataReader
myData = myCommand.ExecuteReader()
myData.Read()

cmbUserName.Text = CStr(myData("username"))

Catch ex As Exception
MsgBox("User Name not found!")

Finally
conn.Close()
End Try
End Sub
When i click the search button, why can not display the data from database into combobox? What's wrong with my code? Anyone can help me solve this problem?

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by GeekByChoiCe
0

Source program must be surrounded with BB code tags: See # icon at toolbar and also read How to use bb code tags?.

>When i click the search button, why can not display the data from database into combobox? What's wrong with my code? Anyone can help me solve this problem?

May be username is blank?

Post your complete code with bb code tags.

0

you do in your query:
sqlquery = "SELECT username FROM pass WHERE username = '" & cmbUserName.Text & "'"

but you want to fill this control with the username dont you?

could you please explain a bit more what exactlly you try.
it might help also to set a breakpoint at your query and check what the username is.

but i think you should do:
sqlquery = "SELECT username FROM pass"
and fill the cmbUserName with the return?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.