MySQL -> 你的 SQL 语法错误我该如何解决
MySQL -> You have an error in your SQL syntax error how can i fix this
MySql.Data.MySqlClient.MySqlException: '您的 SQL 语法有误;查看与您的 MySQL 服务器版本相对应的手册,了解在 '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();
}
这是我的代码,所以我不明白为什么我会收到语法错误,而我没有任何语法问题。
not
是 MySQL 中的 reserved word 所以它必须用反引号转义
MySql.Data.MySqlClient.MySqlException: '您的 SQL 语法有误;查看与您的 MySQL 服务器版本相对应的手册,了解在 '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();
}
这是我的代码,所以我不明白为什么我会收到语法错误,而我没有任何语法问题。
not
是 MySQL 中的 reserved word 所以它必须用反引号转义