Page 1 of 1

Database call from 7 using CommerceBuilder.Data?

Posted: Mon Nov 02, 2015 1:05 pm
by vsammons
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;

}

Re: Database call from 7 using CommerceBuilder.Data?

Posted: Mon Nov 02, 2015 8:51 pm
by mazhar
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.