Jevon Jevon - 26 days ago 9
C# Question

Syntax error with sql query

I have this block of code that executes within my function but it keeps saying there is a syntax error. Am I missing something? Because it seems fine to me

string query3 = "INSERT INTO dbo.Liguanea_Progress VALUES('" + comboBox2.Text + "' '" + textBox5.Text + "' '" + textBox2.Text + "' '" + comboBox3.Text + "''" + textBox3.Text + "''" + comboBox1.Text + "');";

Answer

Missing commas and brackets between your values, try something like this

string query3 = "INSERT INTO dbo.Liguanea_Progress VALUES('" + comboBox2.Text + "'),('" + textBox5.Text + "'),('" + textBox2.Text + "'),('" + comboBox3.Text + "'),('" + textBox3.Text + "'),('" + comboBox1.Text + "');";

You'll need brackets around each value if you're inserting multiple values into the same column. If you're inserting this into one row then you're just missing the commas;

string query3 = "INSERT INTO dbo.Liguanea_Progress VALUES('" + comboBox2.Text + "','" + textBox5.Text + "','" + textBox2.Text + "','" + comboBox3.Text + "','" + textBox3.Text + "','" + comboBox1.Text + "');";