Last post Dec 20, 2010 10:22 PM by MisterSnrub
Dec 20, 2010 11:11 AM|MisterSnrub|LINK
I have three ControlParameters in my SQLDataSource all linked to textboxes, and my SelectCommand has SELECT... FROM... WHERE (Field1 = ?) AND (Field2 = ?) AND (Field3 = ?)" This works fine when the user inputs text into all three textboxes, but if the user
inputs text in only one of the three available textboxes, then the query should disregard the other two parts of the WHERE clause. As it is now my query's where clause is "WHERE (Field1 = 'sometext') AND (Field2 = '') AND (Field3 = '')" which is not what
I want. It should just be "WHERE (Field1 = 'sometext')" because the othe two textboxes are empty strings. How do I fix this?
Dec 20, 2010 12:12 PM|sansan|LINK
There are multiple ways to handle the search.
1) You can create a stored procedure and build a dynamic SQL based on the parameter values passed and execute that dynamic SQL.
2) Another way is using (Field1='Something' OR Field2='Something' OR Field3='Something').
Dec 20, 2010 10:22 PM|MisterSnrub|LINK
re option 1: What is the advantage of creating a stored procedure as opposed to creating the FilterExpression string dynamically in the PageLoad event?