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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
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.