我怎麼會在一個MySQL查詢返回的結果轉換爲數組在C#.net /單聲道如何將數據庫查詢結果轉換爲數組?
據我瞭解,你需要與項目陣列將持有的數量定義數組,但據我所知,DataReader的沒有按不會告訴你有很多行被退回。所以我怎樣才能定義一個數組。
到目前爲止,我有:
string sqlWhere;
if ((name != None) && (name != ""))
sqlWhere = "WHERE name LIKE '%"+name+"%'";
if ((company != None) && (company != ""))
if (sqlWhere == "")
sqlWhere = "WHERE company LIKE '%"+company+"%'";
else
sqlWhere = sqlWhere + " AND company LIKE '%"+company+"%'";
if ((dateFrom != None) && (dateFrom != "") && (dateTo != None) && (dateTo != ""))
if (sqlWhere == "")
sqlWhere = "WHERE date(timestampIn) BETWEEN '"+dateFrom+"' AND '"+dateTo+"'";
else
sqlWhere = sqlWhere + " AND date(timestampIn) BETWEEN '"+dateFrom+"' AND '"+dateTo+"'";
IDbCommand dbcmd = this.dbcon.CreateCommand();
dbcmd.CommandText = "SELECT * FROM visitors " + sqlWhere;
MySqlDataReader Reader = dbcmd.ExecuteReader();
while (Reader.Read())
{
}
用上面的代碼,你已經開放給SQL注入 - 這是一個嚴重的安全問題! – Yahia
爲什麼你想要一個數組?創建一個幾乎總是一個壞主意。如果需要,可以將數據採集器直接綁定到網格。 –