Link to home
Create AccountLog in
Avatar of addicktz
addicktz

asked on

SqlDataSource doesn't seem to be using select parameter....

I have an SqlDataSource I am adding a Select Parameter to, the select statement works in the mysql console, if I had to make a guess, it seems like the parameter value isn't being passed correctly. I have googled, and I have tried every combo I can think of escape and operator characters. Any ideas are greatly appreciated.

        workString2 = workString2 + " and workqueuedescription like @search;";
        SqlDataSource2.SelectParameters.Add("search","%" + search + "%");
        SqlDataSource2.SelectParameters["search"].DefaultValue = "'%" + search + "%'";

        SqlDataSource2.SelectCommand = workString2;
        SqlDataSource2.DataBind();
Avatar of JimBrandley
JimBrandley
Flag of United States of America image

If you are using SQL Server, try changing your parameter name to "@search".

Jim
Avatar of addicktz
addicktz

ASKER

I tried that, didn't work =[. Also, I am using MySQL
Sent that too soon. The parameter is named @search in your WHERE clause, so I expect the name needs to be the same when you build the parameter object.

Jim
I have used Oracle and SQL server - will see if I can locate some documentation for MySQL.

Jim
Thank you =]
ASKER CERTIFIED SOLUTION
Avatar of JimBrandley
JimBrandley
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
absolutely amazing, where did you find that information? Also, did it perhaps say, if I wanted to use the same parameter more than once? for instance,

workString2 = workString2 + " and (workqueuedescription like ? or workqueuename like ?;";

Thank you so much! =]

-Jeff
I searched this site for MySQL. I think you will have to add the parameter more than once if you want to use it more than once. AS:
workString2 = workString2 + " and (workqueuedescription like ? or workqueuename like ?;";

Then -
SqlDataSource2.SelectParameters.Add("search","%" + search1 + "%");
SqlDataSource2.SelectParameters.Add("search","%" + search2 + "%");

Glad it helped.

Jim