System.Data.SqlClient.SqlException:““=”附近有语法错误。”

这是跟着视频博主打的DataGridView修改操作,但是博主打的时候没有报错而我的却报错了,实在找不出原因,只能麻烦大家帮帮忙啦,谢谢大家!

    private void splitContainer1_Panel1_Paint(object sender, PaintEventArgs e)
    {

    }
    DBHelper dbHelper = new DBHelper();
    //加载窗体时,操作
    SqlDataAdapter adapter = null;
    DataSet ds = null;
    private void FrmEdit_Load(object sender, EventArgs e)
    {// TODO: 这行代码将数据加载到表“masterDataSet.ZC”中。您可以根据需要移动或移除它。
        this.zCTableAdapter.Fill(this.masterDataSet.ZC);
        //显示学生信息

        String conStr = "Data Source=.;Initial Catalog=master;Integrated Security=True";
        SqlConnection con = new SqlConnection(conStr);//实例化连接
        con.Open();
        string sql = "select * from ZC";
        SqlCommand cmd = new SqlCommand(sql, con);//一个Sql语句
        SqlDataAdapter adapter = new SqlDataAdapter(cmd);//数据适配器
        DataSet ds = new DataSet();//DataSet表示数据在内存中的缓存
        adapter.Fill(ds, "ZC");//适配器匹配数据
        dgv_JZGList.DataSource = ds;//dataGridView1的数据源设为ds
        dgv_JZGList.DataMember = "ZC";//绑定ds的表名
        con.Close();//关闭数据库连接
        con.Dispose();//释放资源

    }
    //修改
    private void btnUpdate_Click(object sender, EventArgs e)
    {
        DialogResult result = MessageBox.Show("确定要修改吗?", "提示信息", MessageBoxButtons.YesNo);
        if (result == DialogResult.Yes)
        {
            SqlCommandBuilder builder = new SqlCommandBuilder();//需要参数
            adapter.Update(ds, "ZC");//修改数据集

        }

    }
    //选中某行单元格(单击事件)
    private void dgv_CellClick(object sender, DataGridViewCellEventArgs e)
    {

        if (dgv_JZGList.CurrentRow.Selected)
        {

            //将dgv中的行数据显示到修改编辑区域
            //1.获取dgv行中的数据
            int i = dgv_JZGList.CurrentRow.Index;
            ZGH.Text = dgv_JZGList.Rows[i].Cells["ID"].Value.ToString();
            MM.Text = dgv_JZGList.Rows[i].Cells["Pwd"].Value.ToString();
            name.Text = dgv_JZGList.Rows[i].Cells["XM"].Value.ToString();
            Sex.Text = dgv_JZGList.Rows[i].Cells["XB"].Value.ToString();
            NL.Text = dgv_JZGList.Rows[i].Cells["Age"].Value.ToString();
            DH.Text = dgv_JZGList.Rows[i].Cells["Phone"].Value.ToString();
            cboCollege.Text = dgv_JZGList.Rows[i].Cells["CollegeID"].Value.ToString();
            cboPosition.Text = dgv_JZGList.Rows[i].Cells["Position"].Value.ToString();
        }
    }

    private void btnUpdataBC_Click(object sender, EventArgs e)
    {
        String conStr = "Data Source=.;Initial Catalog=master;Integrated Security=True";
        SqlConnection con = new SqlConnection(conStr);//实例化连接
        con.Open();
        string sql = "updata ZC set txtID= '" + ZGH.Text + "', name= '" + name.Text + "',Sex= '" + Sex.Text + "',Age= '" + NL.Text + "',Phone= '" + DH.Text + "',CollegeID= '" + cboCollege.Text + "',PositionID = '" + cboPosition.Text + " '  where txtID= '" + ZGH.Text + "'";

        SqlCommand cmd = new SqlCommand(sql, con);//一个Sql语句
        int i = cmd.ExecuteNonQuery();

        if (i > 0)
        {
            MessageBox.Show("修改成功");
        }
        else
        {
            MessageBox.Show("修改失败");




img

img

原来是我的update写错了,写成了updata