G
Guest
Hello.
I'm having trouble using the SQL LIKE keyword in the WHERE clause.
Specifically I have trouble using parameters like so (running against SQL
Server):
SqlCommand cmd = new SqlCommand(
"SELECT * FROM Users WHERE first_name LIKE @first_name AND last_name
LIKE @last_name", conn);
SqlParameter param = new SqlParameter();
param.ParameterName = "@first_name";
param.Value = "Jo%";
cmd.Parameters.Add(param);
SqlParameter param = new SqlParameter();
param.ParameterName = "@last_name";
param.Value = "Sm%";
cmd.Parameters.Add(param);
The query doesn't return anything, but that table contains a row with Joe
Smith, which does turn up when I run the query in the Query Analyzer. I've
done w workaround to do text substitution for now, but that's not the correct
way to handle this. Any ideas? Thanks
I'm having trouble using the SQL LIKE keyword in the WHERE clause.
Specifically I have trouble using parameters like so (running against SQL
Server):
SqlCommand cmd = new SqlCommand(
"SELECT * FROM Users WHERE first_name LIKE @first_name AND last_name
LIKE @last_name", conn);
SqlParameter param = new SqlParameter();
param.ParameterName = "@first_name";
param.Value = "Jo%";
cmd.Parameters.Add(param);
SqlParameter param = new SqlParameter();
param.ParameterName = "@last_name";
param.Value = "Sm%";
cmd.Parameters.Add(param);
The query doesn't return anything, but that table contains a row with Joe
Smith, which does turn up when I run the query in the Query Analyzer. I've
done w workaround to do text substitution for now, but that's not the correct
way to handle this. Any ideas? Thanks