0

我有一个数据网格视图。我从数据库中提取数据并显示在这个 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;
                }
            }
4

3 回答 3

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='?'
于 2013-09-11T11:33:22.167 回答
1

,之前的查询中有额外内容where

像这样替换您的查询

string update = "update Tank_Head set Item_Code='?', Opening_Bal='?', Tank_Description='?'  where Tank_Unit='?' and companyID='?'";
于 2013-09-11T11:33:23.700 回答
0

在最后一个字段被更新导致错误之后,您有一个逗号。尝试将语句更改为

string update = "update Tank_Head set Item_Code='?', Opening_Bal='?', Tank_Description='?' where Tank_Unit='?' and companyID='?'";
于 2013-09-11T11:34:53.163 回答