AC 7.0 - Querying DB option removed?

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
User avatar
AbleOne
AbleCommerce Partner
AbleCommerce Partner
Posts: 28
Joined: Thu Jan 22, 2004 3:47 pm
Location: Laguna Hills, CA
Contact:

AC 7.0 - Querying DB option removed?

Post by AbleOne » Wed Dec 05, 2007 1:57 pm

Hi Mike / Logan,
We used to have the nice hooks in 5.5 (cbDatabase Class - QueryArray, QueryArrayIC, QueryValue, etc) for querying the database from the codebehind without having to setup connection, recordset, etc... it was VERY useful for adhoc queries.

I don't see that in 7.0 API... do you still have it? If so, can you provide help on where it is?

If not, the connection string is encrypted and not sure which method to use to unencrypt it...

Let us know?

Thanks.
-sri
sri@awcs.net

User avatar
Logan Rhodehamel
Developer
Developer
Posts: 4116
Joined: Wed Dec 10, 2003 5:26 pm

Post by Logan Rhodehamel » Wed Dec 05, 2007 5:42 pm

We have a similar database wrapper in AC7, though it is provided by the Microsoft enterprise library. Our database class is Microsoft.Practices.EnterpriseLibrary.Data.Database.

CommerceBuilder.Common.Token is a singleton, it provides a static property to get the current instance of the token:

Code: Select all

Token acToken = Token.Instance;
The token instance holds a reference to the database.

Code: Select all

Microsoft.Practices.EnterpriseLibrary.Data.Database database;
database = Token.Instance.Database;
The database class has useful methods like ExecuteScalar, ExecuteDataSet, and ExecuteReader. You can use these methods with ad-hoc queries. They can be used with parameters as well.

Example from our code of ExecuteScalar:

Code: Select all

            int storeId = Token.Instance.StoreId;
            Database database = Token.Instance.Database;
            DbCommand selectCommand = database.GetSqlStringCommand("SELECT COUNT(*) AS TotalRecords FROM ac_ErrorMessages WHERE StoreId = @storeId");
            database.AddInParameter(selectCommand, "@storeId", System.Data.DbType.Int32, storeId);
            return CommerceBuilder.Utility.AlwaysConvert.ToInt(database.ExecuteScalar(selectCommand));
Hope this gets you pointed in the right direction.
Cheers,
Logan
Image.com

If I do not respond to an unsolicited private message, it's not because I'm ignoring you. It's because the answer to your question is valuable to others. Try the new topic button.

User avatar
AbleOne
AbleCommerce Partner
AbleCommerce Partner
Posts: 28
Joined: Thu Jan 22, 2004 3:47 pm
Location: Laguna Hills, CA
Contact:

Post by AbleOne » Wed Dec 05, 2007 9:47 pm

Awesome Logan.. thank you for the quick response.

Will try and see if I run into any issues.

Thanks.
-sri
sri@awcs.net

Post Reply