【发布时间】:2013-06-02 05:48:44
【问题描述】:
我有一个数据网格,我应该将其列值插入到 access 数据库中,但 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之前调试并设置断点并检查query。手动在数据库上测试它。避免这些错误,您可以使用参数。
标签: c# ms-access ms-access-2007