Portal Engine Questions on portal engine and web parts.
Version 6.x > Portal Engine > Providing a variable to SQLDataSource View modes: 
User avatar
Member
Member
treehan77-gmail - 8/3/2012 4:29:41 PM
   
Providing a variable to SQLDataSource
How may i provide a variable to my SQL query in SQLDataSource? For example, I have a query that returns an Employer Names and dollar amounts (thru the use of BasicDataList at the moment). I would like the user to to be able to enter the associated EmployerID and return only the name and amount for that employer.

Thanks!

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 8/4/2012 8:32:55 AM
   
RE:Providing a variable to SQLDataSource
Hello,

You can use a datasource filter as described in this article.

Best regards,
Boris Pocatko

User avatar
Member
Member
treehan77-gmail - 8/6/2012 8:08:27 AM
   
RE:Providing a variable to SQLDataSource
Is there no other way to simply supply a variable to my SQL query. Really, I have to write all this code and modules just to tell a query I only want Employers with > $500 to display? That seems a little crazy

User avatar
Member
Member
treehan77-gmail - 8/6/2012 8:19:51 AM
   
RE:Providing a variable to SQLDataSource
So there is no built-in method of doing this included in Kentico?

User avatar
Member
Member
treehan77-gmail - 8/6/2012 11:18:39 AM
   
RE:Providing a variable to SQLDataSource
I don't want to filter, I want to provide a variable to the query

User avatar
Certified Developer 8
Certified Developer 8
Jiveabillion - 8/6/2012 5:23:46 PM
   
RE:Providing a variable to SQLDataSource
If you can get your variable into a querystring parameter then it's easy to pass it to your SQL Datasource.
for the url "/yourpage.aspx?empid=1234"
Just do this in the where clause:


WHERE EmployeeID = '{%empid%}'
-- OR to use the same datasource for when the querystring doesnt exist
WHERE ('{%empid%}' = '' OR EmployeeID = '{%empid%}')
-- I can't remember for sure, but I don't think Kentico automatically makes querystring parameter macro values SQL Safe, so you might need to replace {%empid%} in the above examples with {%SQLEscape(Querystring["empid"])%}