我有一個數據網格,我應該將其列值插入到訪問數據庫,但我有問題command.ExecuteNonQuery();
數據庫錯誤:「沒有給出一個或多個必需參數的值。」
我的項目沒有完成,只是因爲這個錯誤。這是我的代碼:
for (int i = 0; i < (dataGridFactorRent.Rows.Count) - 1; i++)
{
string query =
@"INSERT INTO tbl_RentFactor([ID],DateNow,customerName, objectName,
objectNumber,unitCost,objectCost,paidMoney,restOfMonyy,customerID,DateBack)
VALUES ("+ID+",'" + lbldate.Text + "','" + cmdCustomName.Text + "'," +
dataGridFactorRent.Rows[i].Cells[1].Value + ",
" + dataGridFactorRent.Rows[i].Cells[3].Value + ",
" + dataGridFactorRent.Rows[i].Cells[4].Value + ",
" + dataGridFactorRent.Rows[i].Cells[5].Value + ",
'" + txtPaid.Text + "','" + lblRemained.Text + "',
"+customerID+",'"+lbldate.Text+"')";
con.Open();
command.CommandText =query;
command.ExecuteNonQuery();
con.Close();
在ExecuteNonQuery之前調試並設置斷點並檢查查詢。在數據庫上手動測試它。避免那些可以使用參數的錯誤。 – Damith