這裏是我的代碼:任何想法爲什麼一個分配語句有效,另一個不行?
string strSQL = "SELECT * from tMedia where SKU = '" + SKU + "'";
FbCommand command = new FbCommand(strSQL, databaseConn);
if (databaseConn.State == ConnectionState.Closed)
databaseConn.Open();
FbDataReader data = command.ExecuteReader();
data.Read(); // only one row is returned
// assignment to "x" is empty (277?)
string x = (string)data["ProductType"].ToString();
// find product type and set flag for later testing
// obviously, these don't work either!
if (data["ProductType"].ToString().Contains("Video "))
videoFormat = true;
else if (data["ProductType"].ToString().Contains("Music: "))
audioFormat = true;
// coProductType.Text assignment is correct
coProductType.Text = data["ProductType"].ToString();
關於SQL注入和不使用參數化查詢不好的評論。 – Yuck
這是有點不清楚你問的。 277在哪裏進來?你爲什麼要調用ToString *和* casting? –
關於不使用'using'塊的評論(Firebird文檔確實使用它們)。 –