[英]Access database error :“Syntax Error in UPDATE statement.” in c#
我有一個datagridview。 我從數據庫中獲取數據並在此gridview中顯示。 但是,當我嘗試通過單擊按鈕更新它時,它顯示錯誤。
try
{
string update = "update Tank_Head set Item_Code='?', Opening_Bal='?', Tank_Description='?', where Tank_Unit='?' and companyID='?'";
OleDbCommand cmd = new OleDbCommand(update, con);
cmd.Parameters.AddWithValue("@Item_Code", cbItemEdit.Text);
cmd.Parameters.AddWithValue("@Opening_Bal", txtOpeningBalanceEdit.Text);
cmd.Parameters.AddWithValue("@Tank_Description", txtTankDesEdit.Text);
cmd.Parameters.AddWithValue("@Tank_Unit", txtTankUnitEdit.Text);
cmd.Parameters.AddWithValue("@companyID", label1.Text);
i = cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
finally
{
con.Close();
if (i != 0)
{
pnlView.Visible = true;
pnlEdit.Visible = false;
}
}
你在那里有一個流浪逗號:
update Tank_Head set Item_Code='?', Opening_Bal='?', Tank_Description='?', <<< where Tank_Unit='?' and companyID='?'
刪除它,它應該工作正常:
update Tank_Head set Item_Code='?', Opening_Bal='?', Tank_Description='?' where Tank_Unit='?' and companyID='?'
在你的查詢之前有額外的,
在where
像這樣替換你的查詢
string update = "update Tank_Head set Item_Code='?', Opening_Bal='?', Tank_Description='?' where Tank_Unit='?' and companyID='?'";
更新最后一個字段后出現錯誤導致錯誤。 嘗試將語句更改為
string update = "update Tank_Head set Item_Code='?', Opening_Bal='?', Tank_Description='?' where Tank_Unit='?' and companyID='?'";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.