2016-01-14 92 views
0
 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的消息框中顯示未找到結果?

+0

變化,如果條件',如果搜索> 1'和檢查。 –

+0

它落在其他陳述先生。 –

+0

在while循環中放置斷點並檢查循環是否執行...有時數據記錄器可能有零行。 –

回答

2
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 
      If Result.HasRows Then 
       SDA.Fill(dbDataSet) 
       DataGridView1.DataSource = dbDataSet 
      Else 
       MsgBox("No Datafound") 
      End If 
    End If 
    MysqlConn.Close() 
Catch ex As Exception 

End Try 
+0

這不起作用 –

0
MysqlConn = New MySqlConnection 
MysqlConn.ConnectionString = "server=localhost;userid=root;password=**********;database=librarydb;" 
Dim SDA As New MySqlDataAdapter 
Dim bSource As New BindingSource 

昏暗dbDataSet作爲新的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) 

      If dbDataSet.Rows.count>0 Then 
       DataGridView1.DataSource = dbDataSet 
      Else 
       MsgBox("No Datafound") 
      End If 
    End If 
    MysqlConn.Close() 
Catch ex As Exception 

End Try 
+0

dbDataset不是一個成員System.Data.Set –

+0

其Datatable Pl找到更新ans並且也總是嘗試使用datatable –

+0

什麼DataTablePI先生?我找不到它 –

相關問題