Custom SQL Query in Gold
Posted: Wed Feb 13, 2013 5:09 pm
working with Gold R3. I am in need of accessing data in a custom table that I added to the ac database from my .aspx page. For AC7 I found:
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);
}
in the wiki. This appears that it would allow me to do exactly what I need.
How do I go about getting custom data out of the database in Gold without building from the ground up?
Thanks, Rudy
FYI: The custom table stores customer to products to price relationship. We have a group of chemical products (500+/-) that in order to purchase, customers have to have pre-approval (I am setting a custom field to flag the products where this is the case so that if the visibility for the product is "public", pricing and other custom fields will be hidden - unless an authorized customer is logged in). The set of products (4-8) for each customer is different. As well as each customer may have unique pricing for the product (the custom table). Once a user is logged in, they will have a page showing their "authorized" products with their "special" pricing - and they can order right from that page instead of browsing the catalog or searching. (Most of our sales are repeat b2b). I'm open to suggestions about the best way to do this - a custom table seemed like the way to go.
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);
}
in the wiki. This appears that it would allow me to do exactly what I need.
How do I go about getting custom data out of the database in Gold without building from the ground up?
Thanks, Rudy
FYI: The custom table stores customer to products to price relationship. We have a group of chemical products (500+/-) that in order to purchase, customers have to have pre-approval (I am setting a custom field to flag the products where this is the case so that if the visibility for the product is "public", pricing and other custom fields will be hidden - unless an authorized customer is logged in). The set of products (4-8) for each customer is different. As well as each customer may have unique pricing for the product (the custom table). Once a user is logged in, they will have a page showing their "authorized" products with their "special" pricing - and they can order right from that page instead of browsing the catalog or searching. (Most of our sales are repeat b2b). I'm open to suggestions about the best way to do this - a custom table seemed like the way to go.