MysqlConn = New MySqlConnection
MysqlConn.ConnectionString = "server=localhost;userid=root;password=**********;database=librarydb;"
Dim SDA As New MySqlDataAdapter
Dim bSource As New BindingSource
Dim dbDataSet As New DataTable
Dim ds As New DataSet
Dim Result As MySqlDataReader
Try
MysqlConn.Open()
If ComboBox2.Text = "Author" Then
Dim Query As String
Query = "Select quantity as 'Qty',classification as 'Classification',author as 'Author',title as 'Title',call_number as 'Call Number',isbn_number as'ISBN Number' from librarydb.blist where author like'%" & TextBox1.Text & "%'"
COMMAND = New MySqlCommand(Query, MysqlConn)
SDA.SelectCommand = COMMAND
SDA.Fill(dbDataSet)
Result = COMMAND.ExecuteReader
Dim search As Integer
search = 0
While Result.Read
search = search + 1
End While
If search = 1 Then
SDA.Fill(dbDataSet)
DataGridView1.DataSource = dbDataSet
Else
MsgBox("No Datafound")
MysqlConn.Close()
End If
End If
我想讓我的程序做的事情是如果用戶在組合框中選擇「作者」並在文本框中輸入作者姓名,它將在datagridview中顯示結果。我試過這段代碼,但不起作用。它總是落在else語句中。如何在Vb.net的消息框中顯示未找到結果?
變化,如果條件',如果搜索> 1'和檢查。 –
它落在其他陳述先生。 –
在while循環中放置斷點並檢查循環是否執行...有時數據記錄器可能有零行。 –