我想显示我想要选择的内容,但我只获得了一行。怎么解决它PLZ? 我只获得了第一行数据,但是当我在第二轮中执行do时,它会跳过循环并结束该过程。
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 :(得分:0)
你可能希望在你的LIKE子句周围有一个%,所以:
SQLstring = "SELECT * From record WHERE member_code like '" & u1 & "%' "
这将返回所有具有以u1变量开头的member_code的行。如果你只有那里没有%的变量,它将只返回具有该member_code的行。
此外,与您的问题无关,但与Google“Bobby Tables”和“SQL Injection”无关。