我有一个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;
}
}
答案 0 :(得分:1)
你那里有一个流浪逗号:
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='?'
答案 1 :(得分:1)
,
where
替换你的查询
string update = "update Tank_Head set Item_Code='?', Opening_Bal='?', Tank_Description='?' where Tank_Unit='?' and companyID='?'";
答案 2 :(得分:0)
在更新最后一个字段后出现错误导致错误。尝试将语句更改为
string update = "update Tank_Head set Item_Code='?', Opening_Bal='?', Tank_Description='?' where Tank_Unit='?' and companyID='?'";