0

I use SqlDataSource control to list out search result when user choose a date, but if the date is null, then it will list out all record. How to do the sql command?

SELECT Ref_No as name, Job_Order_ID as value 
FROM Job_Order 
WHERE (Status <> 'JO_Completed') AND (Delivery_Date = @jaDate) 
OR (Status <> 'JO_Completed') ORDER BY Ref_No 

code to generate dropdownlist

 <asp:SqlDataSource ID="NewJobOrderDS" runat="server" SelectCommand="SELECT Ref_No as name, Job_Order_ID as value FROM Job_Order WHERE (Status <> 'JO_Completed') AND (Delivery_Date = @jaDate) ORDER BY Ref_No" OnSelecting="NewJobOrderDS_Selecting">
                                  <SelectParameters>
                                        <asp:ControlParameter ControlID="txtJADate2" Name="jaDate" PropertyName="Text" Type="DateTime"/>   
                                   </SelectParameters>
                                </asp:SqlDataSource>
5
  • are you sure about your query? Prop1 AND Prop2 OR Prop1 = Prop1 always.. no matter what is the truth value of Prop2... all i am trying to say is that your where clause is equivalent with (Status <> 'JO_Completed')
    – avi
    Commented Aug 13, 2013 at 8:17
  • @avi I dunno how to do the query.. The condition is if jaDate = null then i will do select statement WHERE (Status <> 'JO_Completed') else if jaDate have value then select statement WHERE (Status <> 'JO_Completed') AND (Delivery_Date = jaDate) Commented Aug 13, 2013 at 8:24
  • You said: "if the date is null ", does this means your dropdown also has null values? Can you show the same. Also show how data is binded to dropdown
    – R.C
    Commented Aug 13, 2013 at 15:59
  • @FlopScientist Yes. If the date is null,the dropdown also will have the null values. I had edit my post for the code to bind dropdown. Commented Aug 14, 2013 at 0:53
  • 1
    I had solve it by having 2 sqldatasourceID and code for it is protected void txtJADate2_TextChanged(object sender, EventArgs e) { ddlNewJobOrder.DataSourceID = null; if (txtJADate2.Text =="") { ddlNewJobOrder.DataSource = NewJobOrderDS1; } else { ddlNewJobOrder.DataSource = NewJobOrderDS2; } ddlNewJobOrder.DataBind(); } Commented Aug 14, 2013 at 2:47

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.