Saturday, February 25, 2012

Multiple searches for FilterExpression

This is what I have:

<asp:TextBoxID="TextBoxProjectCode"runat="server"></asp:TextBox>

<asp:ButtonID="ButtonSearch"runat="server"Text="Search"/> <br>

<asp:TextBoxID="TextBoxProjectDate"runat="server"></asp:TextBox>

<asp:ButtonID="ButtonSearch"runat="server"Text="Search"/>

SelectCommand="SELECT CLIENT_NAME, CLIENT_CODE, PROJECT_CODE, PROJECT_NAME, PROJECT_DESCRIPTION, EMPLOYEE_ID, ENTRY_DATE, ENTRY_TIME, ENTRY_DESCRIPTION, COMBINED_CODE, TIME_ENTRY_ID, BILLABLE FROM VIEW_TIME WHERE (EMPLOYEE_ID = @.SELECT_EMPLOYEE_ID) ORDER BY ENTRY_DATE DESC"

FilterExpression="PROJECT_CODE = '{0}' or ENTRY_DATE = '#{0}#' "

<FilterParameters>

<asp:ControlParameterControlID="TextBoxProjectCode"Name="PROJECT_CODE"PropertyName="Text"Type="Int32"/>

<asp:ControlParameterControlID="TextBoxProjectDate"Name="ENTRY_DATE"PropertyName="Text"Type="DateTime"/>

</FilterParameters>

Why do I keep getting errors. What am I missing?

Give us a clue, tell us what the errors are?

|||

I changed it to the following, but what I am getting now is that it will not return records unless both textboxes are filled and then it is not returning what I need. I need them to be able to enter in one or the other box and return results based on that criteria. Thanks for your help in advance.Yes

<asp:TextBoxID="TextBoxProjectCode"runat="server"></asp:TextBox>

<asp:ButtonID="ButtonSearch"runat="server"Text="Search"/> <br>

<asp:TextBoxID="TextBoxProjectDate"runat="server"></asp:TextBox>

<asp:ButtonID="ButtonSearch"runat="server"Text="Search"/>

SelectCommand="SELECT CLIENT_NAME, CLIENT_CODE, PROJECT_CODE, PROJECT_NAME, PROJECT_DESCRIPTION, EMPLOYEE_ID, ENTRY_DATE, ENTRY_TIME, ENTRY_DESCRIPTION, COMBINED_CODE, TIME_ENTRY_ID, BILLABLE FROM VIEW_TIME WHERE (EMPLOYEE_ID = @.SELECT_EMPLOYEE_ID) ORDER BY ENTRY_DATE DESC"

FilterExpression="PROJECT_CODE = '{0}' or ENTRY_DATE = '#{1}#' "

<FilterParameters>

<asp:ControlParameterControlID="TextBoxProjectCode"Name="PROJECT_CODE"PropertyName="Text"Type="Int32"/>

<asp:ControlParameterControlID="TextBoxProjectDate"Name="ENTRY_DATE"PropertyName="Text"Type="DateTime"/>

</FilterParameters>

|||

I tend to use the sql where clause rather than filters, just force of habit.

I'm not saying it is better than filters, I just have not got round to learning filters yet.

So I would turn the filter parameters into selectparameters and :

select client_name, etc from View_time where (eployee_id=@.select_employee_id)

AND ( project_code = @.project_code OR entry_date = @.entry_date)

Optionally you could use a runType parameter connected with which textboxes the users filled in, or a dropdown or radio buttons or whatever you like:

select client_name, etc from View_time where (eployee_id=@.select_employee_id)

AND ( ( @.runType = 'P' and project_code = @.project_code ) OR ( @.runType = 'R' and entry_date = @.entry_date ) )

No comments:

Post a Comment