-1

When I run the ide show the following exception

System.Data.SqlClient.SqlException: 'Incorrect syntax near '='.'

string query = "SELECT * FROM lwpos_categories  WHERE parent_id=" + ddlCategory.SelectedValue;
hornet
  • 5
  • 2
  • 5

1 Answers1

0

Probably ddlCategory.SelectedValue is empty. The following can fix this exception (and I recommend using SqlParameters).

string query = "SELECT * FROM lwpos_categories  WHERE parent_id= '" + ddlCategory.SelectedValue + "'";
d219
  • 2,707
  • 5
  • 31
  • 36
Serkan Arslan
  • 13,158
  • 4
  • 29
  • 44
  • 2
    I think it would have been better to give a really, really strong warning about why this code is dangerous rather than just mentioning `SqlParameter` in parentheses, as if it's something that's not really important. – Jon Skeet Nov 25 '19 at 14:35