mysql - >您在SQL语法中有一个错误,我该如何解决此问题

发布于 2025-01-27 09:57:42 字数 1801 浏览 3 评论 0原文

mysql.data.mysqlclient.mysqlexception:'您的SQL语法中有一个错误;检查与您的MySQL Server版本相对应的手册,以了解要使用的正确语法“ not = 41,durum ='basarisiz'其中id = 2'在第1行'

    int i = 0;
    private void button2_Click(object sender, EventArgs e)
    {
        int not = Convert.ToInt16(comboBox5.Text) + Convert.ToInt16(comboBox3.Text) + Convert.ToInt16(comboBox4.Text) + Convert.ToInt16(comboBox6.Text) + Convert.ToInt16(comboBox7.Text) + Convert.ToInt16(comboBox8.Text) + Convert.ToInt16(comboBox9.Text) + Convert.ToInt16(comboBox10.Text) + Convert.ToInt16(comboBox11.Text) + Convert.ToInt16(comboBox12.Text) + Convert.ToInt16(comboBox13.Text) + Convert.ToInt16(comboBox14.Text) + Convert.ToInt16(comboBox15.Text) + Convert.ToInt16(comboBox16.Text) + Convert.ToInt16(comboBox17.Text) + Convert.ToInt16(comboBox18.Text) + Convert.ToInt16(comboBox19.Text) + Convert.ToInt16(comboBox20.Text) + Convert.ToInt16(comboBox21.Text);


        conn.Open();
        string update = "Update ogrenci Set not=@not, durum=@durum Where id=@id";
        cmd = new MySqlCommand(update, conn);

        cmd.Parameters.AddWithValue("@not", not);
        cmd.Parameters.AddWithValue("@durum", comboBox22.Text);
        cmd.Parameters.AddWithValue("@id", dataGridView1.Rows[i].Cells[0].Value);

        cmd.ExecuteNonQuery();

        MessageBox.Show("Başarıyla Güncellendi.");

        conn.Close();

        getOgrenci();
    }
    private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
    {
        i = e.RowIndex;
        textBox1.Text = dataGridView1.Rows[i].Cells[2].Value.ToString();
        textBox4.Text = dataGridView1.Rows[i].Cells[3].Value.ToString();
        textBox2.Text = dataGridView1.Rows[i].Cells[6].Value.ToString();
    }

有我的代码,所以我不明白为什么我会得到我的代码语法错误,而我没有任何语法问题。

MySql.Data.MySqlClient.MySqlException: 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'not=41, durum='BASARISIZ' Where id=2' at line 1'

    int i = 0;
    private void button2_Click(object sender, EventArgs e)
    {
        int not = Convert.ToInt16(comboBox5.Text) + Convert.ToInt16(comboBox3.Text) + Convert.ToInt16(comboBox4.Text) + Convert.ToInt16(comboBox6.Text) + Convert.ToInt16(comboBox7.Text) + Convert.ToInt16(comboBox8.Text) + Convert.ToInt16(comboBox9.Text) + Convert.ToInt16(comboBox10.Text) + Convert.ToInt16(comboBox11.Text) + Convert.ToInt16(comboBox12.Text) + Convert.ToInt16(comboBox13.Text) + Convert.ToInt16(comboBox14.Text) + Convert.ToInt16(comboBox15.Text) + Convert.ToInt16(comboBox16.Text) + Convert.ToInt16(comboBox17.Text) + Convert.ToInt16(comboBox18.Text) + Convert.ToInt16(comboBox19.Text) + Convert.ToInt16(comboBox20.Text) + Convert.ToInt16(comboBox21.Text);


        conn.Open();
        string update = "Update ogrenci Set not=@not, durum=@durum Where id=@id";
        cmd = new MySqlCommand(update, conn);

        cmd.Parameters.AddWithValue("@not", not);
        cmd.Parameters.AddWithValue("@durum", comboBox22.Text);
        cmd.Parameters.AddWithValue("@id", dataGridView1.Rows[i].Cells[0].Value);

        cmd.ExecuteNonQuery();

        MessageBox.Show("Başarıyla Güncellendi.");

        conn.Close();

        getOgrenci();
    }
    private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
    {
        i = e.RowIndex;
        textBox1.Text = dataGridView1.Rows[i].Cells[2].Value.ToString();
        textBox4.Text = dataGridView1.Rows[i].Cells[3].Value.ToString();
        textBox2.Text = dataGridView1.Rows[i].Cells[6].Value.ToString();
    }

there is my code so i don't understand why i am getting syntax error while i don't have any syntax issue.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

病女 2025-02-03 09:57:42

不是保留字 mysql,因此必须用后滴答逃脱

not is a reserved word in MySQL so it must be escaped with back ticks

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文