ObjectDataSource: How to add additional select conditions? RRS feed

  • Question

  • User260076833 posted


    I am new to accessing the database using a "data link layer" and an ObjectDataSource.

    My application presents a list of rooms to the user. The user may specify and change some conditions and the list is updated according to these conditions.

    I have made a database function "RoomMatch(@idx,@d0,@d1,@@arr)". This function determins, if a single room (identified by index @idx) matches the conditions, e. g. if it is free during datetime interval (@d0,@d1) or if it allows for a special arrangement of chairs (@arr).

    Then, I have created a DataSet with a SQL query "GetByMatch" like this:

    SELECT idx,name,organization,RoomMatch(idx,@d0,@d1,@arr) as match;

    Here, the parameters @d0, @d1 and @arr are also parameters for the DataSet query.
    Then, within my GUI I have an ObjectDataSource which uses the DataSet with the method "GetByMatch".

    So far, so good.

    Now I would like to add some additional filter conditions. For example, the rooms have different types and I would like to limit the result list to rooms having some certain types.
    What I need is something like this:

    SELECT * FROM <ObjectDataSource above> WHERE type = 'A' OR type = 'B';

    But I don't want to extend the database function, because I see this in the WHERE condition like in the example above.

    I could imagine the following places to add this:

    • use DataSource.FilterExpression
    • add a new query to the DataSet with additional parameters

    With the first option, I would see the problem that all records are fetched from the database and the condition would be applied then, in a second step. Right?

    With the second option, I don't really know how to do it.

    How would you do this?


    Wednesday, February 24, 2016 7:12 AM