0

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

Edited by mike_2000_17: Fixed formatting

2
Contributors
1
Reply
7
Views
7 Years
Discussion Span
Last Post by Geekitygeek
0

The SelectCommand accepts an instance of the SqlConnection class, not just the query string.
Try sqlDataAdapterSearch.SelectCommand = new SqlCommand("SELECT * FROM Customers WHERE (CustomerID LIKE'" + textBoxSearch.Text + "')"); Although you may want to look at using parameters to make your code easier to read/debug.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.