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?

Recommended Answers

All 2 Replies

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.

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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.