0
我使用下面的代碼從數據庫中選擇數據在某些情況下,這應該返回多個結果,我不知道如何返回所有匹配的結果,如所有預訂時間到一個數組和母雞使用這些在列表框中。OleDbCommand返回多行
myConn.ConnectionString = connection.dbdataSource;
OleDbCommand selectServiceNo = myConn.CreateCommand();
selectServiceNo.CommandText =
"SELECT ID, BookingTime, BookingDate, Description FROM booking";
selectServiceNo.CommandText += " WHERE BookingDate = #";
selectServiceNo.CommandText += dateSelected;
selectServiceNo.CommandText += "#";
myConn.Open();
OleDbDataReader myDR2 = selectServiceNo.ExecuteReader();
while (myDR2.Read())
{
bTime = Convert.ToString(myDR2["BookingTime"]);
bDate = Convert.ToString(myDR2["BookingDate"]);
}
myConn.Close();
您的代碼易受[SQL注入](http://www.troyhunt.com/2013/07/everything-you-wanted-to-know-about-sql.html)的影響。 **從不**使用字符串連接來構建SQL查詢。 **總是**使用參數化查詢。 –