Du mangler simpelthen eksekveringsmetoden. Det afhænger af, hvilken slags resultat du ønsker. Hvis du kun vil have det første resultat fra forespørgslen (første række og første kolonne), så brug sqlcmd.ExecuteScalar()
.
Hvis du vil have alle resultaterne, skal du indlæse det i en MySqlDataReader ved hjælp af metoden sqlcmd.ExecuteReader()
Brug af 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()
Brug af 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()