我正在使用下面的代碼來獲取數據庫中存在的記錄的計數,但不知何故它不工作。查詢獲得來自MS Access數據庫記錄的計數
扔我一個錯誤:
Input string was not in a correct format.
conn.Open();
OleDbCommand cmd1 = new OleDbCommand();
cmd1.CommandText = "select count(*) from Orders_Description where (ItemCode=" + Convert.ToInt32(row.Cells[1].Value) + ") and (OrderId=" + Convert.ToInt32(txtOrderNo.Text) + ")";
int recordExists = Convert.ToInt32(cmd1.ExecuteScalar());
if (recordExists > 0)
{
//Insert command if record exists.
}
「row.Cells [1] .Value」和「txtOrderNo.Text」的值究竟是什麼?什麼是你的「CurrentCulture」?調試您的代碼並告訴我們。並且請始終使用[參數化查詢](http://blog.codinghorror.com/give-me-parameterized-sql-or-give-me-death/)。這種字符串連接對於[SQL注入](http://en.wikipedia.org/wiki/SQL_injection)攻擊是開放的。 –
'row.Cells [1] .Value'和'txtOrderNo.Text'包含整數值,並且在數據庫中也有一個整型 –
您的評論根本沒有幫助。這些值完全**是什麼? 「ItemCode」和「OrderId」列的類型是什麼? –