im trying to retrieve mysql data with specific column and show to textbox in vb.net. what should i do in retrieving it?
Dim connect As New MySqlConnection("server=localhost; user id=root; password= ; database=ticketing_system;")
connect.Open()
Dim sqladapter As New MySqlDataAdapter
Dim sqlcmd As New MySqlCommand
Dim dr As MySqlDataReader
Dim dt As New DataTable
sqlcmd = New MySqlCommand("SELECT * complaint WHERE tran_no='" & lbltranno.Text & "'")
**THEN? WHAT SHOULD I DO TO DISPLAY DATA? PLEASE HELP**
connect.Close()
Try this one, i always use this code, that's why i'm pretty sure that this will work...
'This code display all subject name from the table into labels.This might be helped.
You are simply missing the Execution method. It depends on what kind of result you want. If you only want the first result from the query (first row and first column) then use
sqlcmd.ExecuteScalar()
.If you want all the results you'll have to load that into a MySqlDataReader using the method
sqlcmd.ExecuteReader()
Using
ExecuteReader()
:Using
ExecuteScalar()
:I used a variation of the code given in this thread with Visual Basic 2015. I found I needed a 2nd argument in the MySqlCommand statement, namely the MySqlConnection variable ("connect" in some of the examples). See thread: Connection must be valid and open VB.Net
Thanks for the help.