UPDATE语句中的语法错误 - C#

时间:2013-10-14 04:07:25

标签: c#

  

我一直在尝试从GRIDVIEW更新数据到MSACCESS数据库。但是在执行ExecuteNonQuery语句时,我收到SYNTAX错误更新语句的错误。请帮助我....我的问题可能类似于几个人发布的那些..但我的代码与其他人的代码不同..请快速回复...在下面的代码中这是行           cmd.ExecuteNonQuery();我收到错误的地方...... plz..plz帮帮我

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
    OleDbConnection con = new OleDbConnection(constr);
    con.Open();    
    string name = GridView1.DataKeys[e.RowIndex].Values["SName"].ToString();
    TextBox day = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox1");
    string com = "update enroll set Day = '?' where SName = '?'";
    OleDbCommand cmd = new OleDbCommand(com, con);
    cmd.Parameters.AddWithValue("@Day", day.Text.ToString());
    cmd.Parameters.AddWithValue("@SName", name.ToString());
    cmd.ExecuteNonQuery();
    con.Close();
    Label3.ForeColor = Color.Green;
    Label3.Text = name + " Details Updated successfully";
    GridView1.EditIndex = -1;
}

1 个答案:

答案 0 :(得分:4)

更改string com = "update enroll set Day = '?' where SName = '?'";

string com = "update enroll set Day = ? where SName = ?";

由于您在?之前和之后都有引号,因此不会将其视为参数