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
theLizardPosted Aug 2, 2010, 7:25 PM
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.
Ryan ThomasPosted Aug 2, 2010, 7:13 PM
thanks
theLizardPosted Aug 2, 2010, 7:07 PM
try the following.
SqlConnection con = new SqlConnection();
SqlCommand cmd = new SqlCommand("SELECT * FROM Customers WHERE CustomerID LIKE" + textBoxSearch.Text, con);
cmd.ExecuteNonQuery();
Ryan ThomasPosted Aug 2, 2010, 6:46 PM
"SELECT * FROM Customers WHERE CustomerID LIKE" + textBoxSearch.Text + "";
the same error comes up with this code too
theLizardPosted Aug 2, 2010, 6:30 PM
This is wrong
Remove ( and ) if textbox represents an int for id do not enclose in single quotes ' and '