Anda hanya melewatkan metode Eksekusi. Itu tergantung pada hasil seperti apa yang Anda inginkan. Jika Anda hanya menginginkan hasil pertama dari kueri (baris pertama dan kolom pertama), gunakan sqlcmd.ExecuteScalar()
.
Jika Anda menginginkan semua hasil, Anda harus memuatnya ke dalam MySqlDataReader menggunakan metode sqlcmd.ExecuteReader()
Menggunakan 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()
Menggunakan 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()