i'm attempting to use a select statement which retrieves products 'LIKE' textbox.text. However, i am given an error and cannot find a solution
private void buttonSearch_Click(object sender, EventArgs e)
{
if (radioButtonCustomerID.Checked == true)
{
try
{
sqlConnectionNW.Open();
sqlDataAdapterSearch.SelectCommand = "SELECT * FROM Customers WHERE (CustomerID LIKE'" + textBoxSearch.Text + "')";
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
sqlConnectionNW.Close();
}
}
the eror given is "cannot implicitly convert type 'string' to 'System.Data.SqlClient.SqlCommand"
Any help would be highly appreciated as it has stopped me dead in my tracks
thanks
Loading

theLizardRank #1,079 · 1.8K reputationPosted Aug 2, 2010, 2:30 PM EDT
This is wrong
Remove ( and ) if textbox represents an int for id do not enclose in single quotes ' and '
Ryan Thomas13 reputationPosted Aug 2, 2010, 2:46 PM EDT
"SELECT * FROM Customers WHERE CustomerID LIKE" + textBoxSearch.Text + "";
the same error comes up with this code too
theLizardRank #1,079 · 1.8K reputationPosted Aug 2, 2010, 3:07 PM EDT
try the following.
SqlConnection con = new SqlConnection();
SqlCommand cmd = new SqlCommand("SELECT * FROM Customers WHERE CustomerID LIKE" + textBoxSearch.Text, con);
cmd.ExecuteNonQuery();
Ryan Thomas13 reputationPosted Aug 2, 2010, 3:13 PM EDT
thanks
theLizardRank #1,079 · 1.8K reputationPosted Aug 2, 2010, 3:25 PM EDT
I do not work with data bound controls ever, so I am not sure what needs to be done in regards to the use of data adapters.
Look at SqlCommand help and see how it is used with data adapters it may be very simple.