• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 582
  • Last Modified:

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();
0
addicktz
Asked:
addicktz
  • 5
  • 3
1 Solution
 
JimBrandleyCommented:
If you are using SQL Server, try changing your parameter name to "@search".

Jim
0
 
addicktzAuthor Commented:
I tried that, didn't work =[. Also, I am using MySQL
0
 
JimBrandleyCommented:
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
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

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

Jim
0
 
addicktzAuthor Commented:
Thank you =]
0
 
JimBrandleyCommented:
If you are using ODBC, it doesn't take named parameters, in that case, change your where clause to:
workString2 = workString2 + " and workqueuedescription like ?;";

and the parameter should be good as it is. They are referenced by position instead of name.

Jim

0
 
addicktzAuthor Commented:
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
0
 
JimBrandleyCommented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now