-1

I keep having this error 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 'Name like 'f'' at line 1 i want to filter data

This is my code can someone help me

MySqlConnection connection = new MySqlConnection(MyConnection);
connection.Open();

DataTable dt = new DataTable();
MySqlDataAdapter da = new MySqlDataAdapter("Select * from new_order where Full Name like '" + textBox1.Text + "'", connection);
da.Fill(dt);
dataGridView1.DataSource = dt;

connection.Close();
juharr
  • 31,741
  • 4
  • 58
  • 93
ang
  • 1
  • 2
  • 3
    First thing to know: you shouldn't be putting values into your SQL like that. Use parameterized SQL, *right now*. – Jon Skeet Oct 05 '15 at 18:17
  • If *Full Name* really is the name of your column, you probably should enclosed it with backticks, see http://stackoverflow.com/questions/261455/using-backticks-around-field-names. – Fasermaler Oct 05 '15 at 19:11

2 Answers2

0

To use a space in a column name you have to put it in square brackets:

"select * from new_order where [Full Name] like ..."

And never concatenate your queries like this, it makes you vulnerable to SQL injection attacks. Use parameters.

Jakub Lortz
  • 14,616
  • 3
  • 25
  • 39
0

If the column Full Name has a space in it it must be wrapped in quotes to be read by the SQL.

i.e. "Select * from new_order where 'Full Name' like '" + textBox1.Text + "'"

I haven't tested this but it should work.

calderonmluis
  • 547
  • 4
  • 11