Database call from 7 using CommerceBuilder.Data?

For general questions and discussions specific to the AbleCommerce GOLD ASP.Net shopping cart software.
Post Reply
User avatar
vsammons
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 33
Joined: Mon May 10, 2010 7:10 am

Database call from 7 using CommerceBuilder.Data?

Post by vsammons » Mon Nov 02, 2015 1:05 pm

I had some custom code in version 7.x that was using CommerceBuilder.Data; What is the reference in Gold. I am new to the Gold code but finding my way around for the most part. This has me a little stumped. If someone has a few minutes to help would be appreciated! Thanks in advance!

I had built a table to store customer notes and used "Database database = Token.Instance.Database;":

public string loadusernotes()
{
string Notes = string.Empty;


Database database = Token.Instance.Database;
DbCommand selectcommand = database.GetSqlStringCommand("select Notes from ac_UserNotes where UserId='"+ _UserId +"'");
database.AddInParameter(selectcommand, "@userId", System.Data.DbType.Int32, _UserId);
using (IDataReader reader = database.ExecuteReader(selectcommand))
{
while (reader.Read())
{
Notes = reader[0].ToString();
}
}
return Notes;

}

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

Re: Database call from 7 using CommerceBuilder.Data?

Post by mazhar » Mon Nov 02, 2015 8:51 pm

Gold makes use of Nhibernate for data access so you have to adjust your queries accordingly.

Code: Select all

public string loadusernotes()
        {
            string Notes = string.Empty;


            var selectcommand = CommerceBuilder.DomainModel.NHibernateHelper.CreateSQLQuery("select Notes from ac_UserNotes where UserId='" + _UserId + "'");
            selectcommand.SetParameter("userId", _UserId);
            Notes = selectcommand.UniqueResult<string>();
            return Notes;

        }
Please have a look at this thread viewtopic.php?f=47&t=17108 I have posted some details about porting AC7 codes to Gold standards.

Post Reply