locked
using the query builder to produce a list of items if a condition is true RRS feed

  • Question

  • User-2000957478 posted

    Hi there, I'm using the query builder in Visual web developer 2010 express and I'm trying to make a query a sql datasource.

    The "top down" description of the query would be this:

    select for each index in the table column(s) A,B,C if D greater than E,

    or If D > E write then write out A,B,C (i'm sure you have it by now)

    I want to get D and E from the datagrid, not have to type anything in so I dont want a control on the form.

    I just want the form to load and list all items (A,B,C) IF THE VALUE IN COLUMN D IS GREATER THAN COLUMN E.

    Ive been playing around with the query builder and can get D from the WHERE clause but always seem to end up having to

    enter a parameter for E, (not practical for couple hundred items)

    oh and the paramters are integers by the way

     

    thanks in advance for any suggestions Laughing

    Wednesday, April 20, 2011 1:36 AM

Answers

  • User373017724 posted

     protected void Page_Load(object sender, EventArgs e)
        {

              --reload the datagrid, everytime
              datagrid.DataBind();
        }

     

    select table.a, table.b, table.c

    From table

    where table.d > table.e

     

    ^^^^^^^^^^^ something along those lines for the sqldatasource?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 20, 2011 1:07 PM

All replies

  • User373017724 posted

     protected void Page_Load(object sender, EventArgs e)
        {

              --reload the datagrid, everytime
              datagrid.DataBind();
        }

     

    select table.a, table.b, table.c

    From table

    where table.d > table.e

     

    ^^^^^^^^^^^ something along those lines for the sqldatasource?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 20, 2011 1:07 PM
  • User3866881 posted

    Hi:)

    My addition to the 2nd man's——

    You should use a SqlDataSource with the 2nd man's advice and have a test, then bind the SqlDataSource to the GridView or DataGrid. Futhermore, I think you should confirm that the column "E: is really in your db, and you can try this way:

    <asp:SqlDataSource …… SelectCommand="select a,b,c from table where d>@e">

       <SelectParameters>

              <asp:Parameter Name="@e" type="Int" DefaultValue="1"/>

       </SelectParameters>

    </asp:SqlDataSource>

    Then handle the SqlDataSource_Selecting event, try to say this:

    e.Parameters["@e"].DefaultValue = Some Value that you want to filter with

    Friday, April 22, 2011 9:04 PM
  • User-2000957478 posted

    Thanks for your help Wink

    Sunday, April 24, 2011 6:16 PM
  • User-2000957478 posted

    Thanks for your help Wink

    Sunday, April 24, 2011 6:17 PM
  • User-2000957478 posted

    select table.a, table.b, table.c

    From table

    where table.d > table.e

     

    I'm going to mark this as answer because it is precisely what I asked for. However the other guys answer was pretty useful too.

     

    Sunday, April 24, 2011 6:21 PM