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
Loading
Ryan ThomasPosted Aug 3, 2010, 7:26 AM
thanks a lot :)
Michael WilliamsPosted Aug 2, 2010, 10:19 PM
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