Tell me I have this code

MySqlCommand cmd = new MySqlCommand("INSERT INTO news (title, body) VALUES(" + textBox1.Text + "," + richTextBox1.Text + ");", cnt); 

And I always have an error as if there is no such column, and if I use this

 MySqlCommand cmd = new MySqlCommand("INSERT INTO news (title) VALUES(\"" + title + "\");", mysqlCon); 

So everything is fine, so you can insert many requests at once?

  • Is there a body field in the news table? richTextBox1.Text randomly does not contain quotes? - KoVadim

2 answers 2

And if so?

 "INSERT INTO news (title, body) VALUES('" + textBox1.Text + "','" + richTextBox1.Text + "');" 
  • Is it possible to also request UPDATE? - Angus123
  • 2
    UPDATE news SET title = '"+ string1 +"', body = '"+ string2 +"' WHERE .... "Use ORM instead of these concatenations, or parameters for worst-case requests. - wind
  • MySqlCommand cmd = new MySqlCommand ("UPDATE news SET date = '" + textBox2.Text + "' title =" "+ textBox1.Text +" ', body =' "+ richTextBox1.Text +" 'WHERE id = "textBox7. Text + ");"); Where is the error here? - Angus123
  • "', title ='" - msi
  • Anyway, the error ... Connection must be valid and open. I use this code> MySqlCommand cmd = new MySqlCommand("UPDATE news SET sitename = '" + null + "', keywords = '" + textBox2.Text + "', description = '" + textBox3.Text + "', seconds = '" + numericUpDown1.Value + "', domen = '" + textBox1.Text + ");"); - Angus123

correct SQL string:

INSERT INTO news (title, body) VALUES ("like a line1", "like a line2");

it means you need to write it correctly in C #. those. recall how to correctly write a quote in a string. the quote in the string looks like this:

"

respectively:

str = "INSERT INTO news (title, body) VALUES (" like a string1 "," like a string2 ");" ;

and in the variant with variables:

str = "INSERT INTO news (title, body) VALUES (" "+ STR1 +" "," "+ STR2 +" ");" ;