Custom Query - Dataset as a result

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
caldog
Ensign (ENS)
Ensign (ENS)
Posts: 1
Joined: Wed Nov 18, 2009 6:55 pm

Custom Query - Dataset as a result

Post by caldog » Thu Nov 19, 2009 3:42 pm

I am using the Token.Instance.Database to execute a custom query in AbleCommerce. The examples on the wiki illustrate getting a scalar result. My question is whether we can get a Dataset returned? I tried it and it appears a Dataset can be returned but I am having trouble getting the results from the Dataset. My code below is:

string sql = ("SELECT CatalogNodeID FROM ac_CatalogNodes WHERE CategoryID IN (SELECT CategoryID FROM ac_Categories WHERE ParentID = 20 and Name = @CategoryID)");

using (System.Data.Common.DbCommand selectCommand = Token.Instance.Database.GetSqlStringCommand(sql))
{
Token.Instance.Database.AddInParameter(selectCommand, "@CategoryID", System.Data.DbType.String, _Category.CategoryId);
System.Data.DataSet dsDiscountedProducts = (System.Data.DataSet)Token.Instance.Database.ExecuteDataSet(selectCommand);
}

Any suggestions on how I loop through the dataset to get the category id's in the dataset?

Thank You,
Calvin

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

Re: Custom Query - Dataset as a result

Post by jmestep » Thu Nov 19, 2009 4:23 pm

Since it's a System.Data.Dataset, you should be able find find info searching in Google or MSDN.
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

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

Re: Custom Query - Dataset as a result

Post by mazhar » Fri Nov 20, 2009 4:39 am

Try something like this with dataset

Code: Select all

string sql = ("SELECT CatalogNodeID FROM ac_CatalogNodes WHERE CategoryID IN (SELECT CategoryID FROM ac_Categories WHERE ParentID = 20 and Name = @CategoryID)");

        using (System.Data.Common.DbCommand selectCommand = Token.Instance.Database.GetSqlStringCommand(sql))
        {
            Token.Instance.Database.AddInParameter(selectCommand, "@CategoryID", System.Data.DbType.String, _Category.CategoryId);
            System.Data.DataSet dsDiscountedProducts = (System.Data.DataSet)Token.Instance.Database.ExecuteDataSet(selectCommand);
            System.Data.DataTable table = dsDiscountedProducts.Tables[0];
            foreach (System.Data.DataRow row in table.Rows)
            {
                int catalogNodeId = AlwaysConvert.ToInt(row["CatalogNodeId"]);
                //Rest of your code here
            }
        }

Post Reply