I have a textbox on my web page that allows the user to search for customers. When they click on search, the following code below is running. I am receiving the error message when trying to populate the data table. Error Message says: Must declare the scalar variable "@SearchParms".
I tried re-testing and hardcoding '%oh%' in place of the @SearchParms and the query worked perfectly and posted the data back correctly. I am racking my brain trying to figure out what I am doing wrong. Can anyone help??
string CustSearch = "'%'" + txtCustSearch.Text + "'%'";
string sql = "SELECT CustomerID, FirstName, LastName, Email, City, State, Phone FROM dbo.Customer WHERE (FirstName LIKE '@SearchParms') OR (LastName LIKE '@SearchParms') OR (City LIKE '@SearchParms') OR (State LIKE '@SearchParms') ORDER BY LastName, FirstName";
//Declare the Command
SqlCommand cmd = new SqlCommand(sql, Conn);
//Add the parameters needed for the SQL query
View Complete Post