locked
Grid view Data source-> OR ,AND in QUERY NOT Returning corrrectly in vb.net RRS feed

  • Question

  • User-1578974752 posted

    <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString3 %>" ProviderName="<%$ ConnectionStrings:ConnectionString3.ProviderName %>" SelectCommand="SELECT &quot;NUMBER&quot;, &quot;LINE&quot; FROM &quot;LINES&quot; WHERE (&quot;NUMBER&quot; = :NUMBER) OR ((&quot;ITEM&quot; = :ITEM) AND (&quot;NUMBER&quot; = :NUMBER))">
                            <SelectParameters>
                                <asp:ControlParameter ControlID="ponumtxt" Name="NUMBER" PropertyName="Text" Type="String" />
                                <asp:ControlParameter ControlID="Partnum" Name="ITEM" PropertyName="Text" Type="String" />
                            </SelectParameters>
                        </asp:SqlDataSource>

    If Number is given in the text biox ,I want to show the grid view . Or If Number and ITEM is given also need to show the grid view .Only one is happening . How can I update

    WHERE (&quot;NUMBER&quot; = :NUMBER) OR ((&quot;ITEM&quot; = :ITEM) AND (&quot;NUMBER&quot; = :NUMBER))">

    so that both condition will work . 1) (&quot;NUMBER&quot; = :NUMBER) 

    2)((&quot;ITEM&quot; = :ITEM) AND (&quot;NUMBER&quot; = :NUMBER)

    Thanks

    Tuesday, January 22, 2019 10:49 AM

Answers

  • User61956409 posted

    Hi shsu,

    user want it to be in two different text boxes.( Number and  Item)

    Even if you set DefaultValue for ControlParameter "ITEM", users can also provide actual input value when using your website.

    With Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 29, 2019 7:07 AM

All replies

  • User61956409 posted

    Hi shsu,

    SelectCommand="SELECT &quot;NUMBER&quot;, &quot;LINE&quot; FROM &quot;LINES&quot; WHERE (&quot;NUMBER&quot; = :NUMBER) OR ((&quot;ITEM&quot; = :ITEM) AND (&quot;NUMBER&quot; = :NUMBER))"

    What's wrong with your select command? Does it not work as expected? Please clarify more about the question/problem.

    Besides, if you'd like to achieve complex query logic, you can try to achieve it from code behind by dynamically set SelectCommand property of your asp:SqlDataSource control.

    'dynamically generate select command based on your business logic
    SqlDataSource3.SelectCommand = "your_select_command_here"

    With Regards,

    Fei Han

    Wednesday, January 23, 2019 2:48 AM
  • User-1578974752 posted

    Thanks . My code is not working as expected. I have 2 textbox (one for Number and other for Item)

    If Number and item is given ,then the grid view is showing correctly. But If I place number only the,values are not retriving.

    some times user will put Number and search.

    some time will put both number and item.

    So 1) If number only  must work  and 2) number and item should work. Appreciate the Help

    Wednesday, January 23, 2019 3:23 AM
  • User61956409 posted

    Hi shsu,

    My code is not working as expected. I have 2 textbox (one for Number and other for Item)

    If Number and item is given ,then the grid view is showing correctly. But If I place number only the,values are not retriving.

    You can try to set a fake default value for ITEM, like below.

    <asp:ControlParameter ControlID="Partnum" Name="ITEM" PropertyName="Text" Type="String" DefaultValue="zzz" />

    With Regards,

    Fei Han

    Wednesday, January 23, 2019 5:23 AM
  • User-1578974752 posted

    But user want it to be in two different text boxes.( Number and  Item)

    Thursday, January 24, 2019 7:33 AM
  • User61956409 posted

    Hi shsu,

    user want it to be in two different text boxes.( Number and  Item)

    Even if you set DefaultValue for ControlParameter "ITEM", users can also provide actual input value when using your website.

    With Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 29, 2019 7:07 AM