2013-05-17 44 views
-1

我想顯示我想要選擇的內容,但我只得到1行。如何解決它PLZ? 我只獲取第一行數據,但是當我在第二輪中執行操作時,它跳過循環並結束該過程。無法在VB.net中查詢多行MySQL數據庫

 
    ListView1.Items.Clear() 


     SQLstring = "SELECT * From record WHERE member_code like '" & u1 & "' " 


     SQLConnection.Open() 
     SQLcommand = New MySqlCommand(SQLstring, SQLConnection) 
     SQLdatareader = SQLcommand.ExecuteReader() 

     Do While SQLdatareader.Read() 
      a = (SQLdatareader.Item("book_code").ToString()) 
      b = (SQLdatareader.Item("member_code").ToString()) 
      c = (SQLdatareader.Item("book_status").ToString()) 
      d = (SQLdatareader.Item("Borrow_date").ToString()) 
      f = (SQLdatareader.Item("Due_date").ToString()) 


      SQLdatareader.Close() 
      SQLcommand.Dispose() 
      SQLConnection.Close() 

      SQLstring = "SELECT * From book WHERE book_code like '" & a & "' " 
      SQLConnection.Open() 
      SQLcommand = New MySqlCommand(SQLstring, SQLConnection) 
      SQLdatareader = SQLcommand.ExecuteReader() 
      Do While SQLdatareader.Read() 
       g = (SQLdatareader.Item("book_name").ToString()) 
       h = (SQLdatareader.Item("book_writer").ToString()) 
       i = (SQLdatareader.Item("book_year").ToString()) 
      Loop 




      Dim SQLlist As ListViewItem = ListView1.Items.Add(g) 
      SQLlist.SubItems.Add(h) 
      SQLlist.SubItems.Add(i) 
      SQLlist.SubItems.Add(d) 
      SQLlist.SubItems.Add(f) 
      If dtNow > f Then 
       Dim fine_amount = f.Subtract(dtNow) 
       SQLlist.SubItems.Add(fine_amount) 

      Else 
       SQLlist.SubItems.Add("0") 
      End If 


     Loop 
     SQLdatareader.Close() 
     SQLcommand.Dispose() 
     SQLConnection.Close() 

    End Sub 

回答

0

你可能想的地方有%左右的LIKE子句,因此:

SQLstring = "SELECT * From record WHERE member_code like '" & u1 & "%' " 

,將返回與您的U1變量開始member_code所有行。如果你只有那裏沒有%的變量,它將只返回具有該member_code的行。

此外,與您的問題沒有關係,但Google「Bobby Tables」和「SQL Injection」。