Mysql
 sql >> Database >  >> RDS >> Mysql

come recuperare i dati di MySQL in vb.net?

Ti manca semplicemente il metodo di esecuzione. Dipende dal tipo di risultato che desideri. Se vuoi solo il primo risultato della query (prima riga e prima colonna), usa sqlcmd.ExecuteScalar() .

Se vuoi tutti i risultati dovrai caricarli in un MySqlDataReader usando il metodo sqlcmd.ExecuteReader()

Usando ExecuteReader() :

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 & "'")
dr = sqlcmd.ExecuteReader()
dt.Load(dr)
'Useable datatable in dt variable...

connect.Close()

Usando ExecuteScalar() :

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 String
Dim dt As New DataTable

sqlcmd = New MySqlCommand("SELECT [COLUMN NAME] complaint WHERE tran_no='" & lbltranno.Text & "'")
dr = sqlcmd.ExecuteScalar()
'dr now contains the value of [COLUMN NAME] for the first returned row.

connect.Close()