Skip to content

Sql select error

Ryan Thomas

Asked Aug 2, 2010, 4:28 PM EDT2 answers
Share
LinkedInX
i've created a select command which then fills a dataset, the input comes from a textbox but when i run the program and searc, i have an error.
private void buttonSearch_Click(object sender, EventArgs e)
{
if (radioButtonCustomerID.Checked == true)
{
try
{
string selectString = "SELECT * FROM Customers WHERE CustomerID LIKE" + textBoxSearch.Text + "";
SqlCommand myCommand = sqlConnectionNW.CreateCommand();
myCommand.CommandText = selectString;
sqlDataAdapterSearch.SelectCommand = myCommand;
sqlConnectionNW.Open();
sqlDataAdapterSearch.Fill(dataSetSearch);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
sqlConnectionNW.Close();
}
}
}
the error i receive once the button is clicked is : an expression of non-boolean type specified in a context where a condition is expected, near 'LIKE'
 
any help on the problem would be appreciated
thanks

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    It looks like you are missing a space between the like and your search box text and that it needs to be in single quotes.  I think it should be something like,
    string selectString = "SELECT * FROM Customers WHERE CustomerID LIKE '" + textBoxSearch.Text + "%'";
    This will search for CustomerID starting with whatever is in textSearchBox.  This is also assuming CustomerID is character
    0
  • 0
    thanks i adjusted it and the select statement fills the gridview nicely
     
    thanks a lot :)
    0