OrderCollection - how to return only the columns I want

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
Mike718NY
Commodore (COMO)
Commodore (COMO)
Posts: 485
Joined: Wed Jun 18, 2008 5:24 pm

OrderCollection - how to return only the columns I want

Post by Mike718NY » Tue Jul 21, 2009 1:36 pm

This returns all the columns in the ac_Orders table:

OrderCollection orderIDs = OrderDataSource.LoadForCriteria("dateOrd = getdate()");
R1.DataSource = orderIDs;

But I really only want one, OrderID, like: "SELECT OrderID FROM ac_Orders WHERE dateOrd = getdate()"

How can I specify my own SQL using the "Data Access Layer" in CommerceBuilder?

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: OrderCollection - how to return only the columns I want

Post by mazhar » Wed Jul 22, 2009 3:09 am

You can iterate over returned order collection and then get order id one by one from each order

Code: Select all

List<int> orderIds = new List<int>();
foreach(Order order in orders)
orderIds.Add(order.OrderId);

Mike718NY
Commodore (COMO)
Commodore (COMO)
Posts: 485
Joined: Wed Jun 18, 2008 5:24 pm

Re: OrderCollection - how to return only the columns I want

Post by Mike718NY » Wed Jul 22, 2009 7:09 am

Don't know if this is ok, but this worked:

string query = "SELECT OrderID FROM ac_Orders WHERE (convert(varchar(10), dateOrd, 101)) = (convert(varchar(10), getdate(), 101))";
Microsoft.Practices.EnterpriseLibrary.Data.Database database = Token.Instance.Database;
System.Data.Common.DbCommand selectCommand = database.GetSqlStringCommand(query);
System.Data.SqlClient.SqlDataReader dr = (System.Data.SqlClient.SqlDataReader)database.ExecuteReader(selectCommand);

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: OrderCollection - how to return only the columns I want

Post by mazhar » Wed Jul 22, 2009 7:16 am

Yep that's fine.

User avatar
jmestep
AbleCommerce Angel
Posts: 8164
Joined: Sun Feb 29, 2004 8:04 pm
Location: Dayton, OH
Contact:

Re: OrderCollection - how to return only the columns I want

Post by jmestep » Wed Jul 22, 2009 7:16 am

Don't forget to wrap it in a using so the connection will be closed. Here is from Able wiki, using code from a newer version of Able where it uses CommerceBuilder.data instead of
Microsoft.Practices.EnterpriseLibrary.Data.Database

CommerceBuilder.Data.Database database = Token.Instance.Database;
string sql = ("SELECT COUNT(*) As RecordCount FROM ac_Affiliates WHERE StoreId = @storeId");
using (System.Data.Common.DbCommand selectCommand = database.GetSqlStringCommand(sql))
{
database.AddInParameter(selectCommand, "@storeId", System.Data.DbType.Int32, Token.Instance.StoreId);
int affiliateCount = (int)database.ExecuteScalar(selectCommand);
}
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx

Post Reply