Menu

Newbie question about criteria groups

Help
2005-02-02
2013-03-22
  • Chris Dunaway

    Chris Dunaway - 2005-02-02

    Following the example for creating criteria groups, I wrote the following code using the Northwind database:

            Dim dm As New DataManager(Config.Dsn)
            dm.QueryCriteria.Clear()

            Dim SubQuery1 As DataManager.CriteriaGroup = dm.QueryCriteria.NewGroup
            Dim SubQuery2 As DataManager.CriteriaGroup = dm.QueryCriteria.NewGroup

            With JoinPath.Orders.Columns
                SubQuery1.And(.OrderDate, #5/6/1998#, MatchType.LesserOrEqual)
                SubQuery1.And(.OrderDate, #1/1/1998#, MatchType.GreaterOrEqual)
            End With

            With JoinPath.Shippers.Columns
                SubQuery2.And(JoinPath.Shippers.Columns.CompanyName, "E", MatchType.Partial)
            End With

            dm.QueryCriteria.And(SubQuery2).And(SubQuery1)

    So my next question is:  What Next?

    I tried calling dm.GetOrdersCollection or dm.GetShippersCollection, but each throws an exception: 

    The column prefix 'Shippers' does not match with a table name or alias name used
    in the query.:    at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBeha

    When I have multiple tables from which to retrieve data, how do I do it?

    Thanks,

    Chris

     
    • Chris Dunaway

      Chris Dunaway - 2005-02-02

      Nevermind, I figured it out myself.  Here is the corrected code snippet:

              With JoinPath.Order.Columns
                  dm.QueryCriteria.And(.OrderDate, #5/6/1998#, MatchType.LesserOrEqual)
                  dm.QueryCriteria.And(.OrderDate, #1/1/1998#, MatchType.GreaterOrEqual)
                  dm.QueryCriteria.And(JoinPath.Order.Shipper.Columns.CompanyName, "Federal Shipping", MatchType.Like)
              End With

              Dim col As OrderCollection = dm.GetOrderCollection(FetchPath.Order.Shipper)

      Simple when you think about it. 

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.