New field in database table

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
User avatar
jmestep
AbleCommerce Angel
Posts: 8164
Joined: Sun Feb 29, 2004 8:04 pm
Location: Dayton, OH
Contact:

New field in database table

Post by jmestep » Thu Dec 04, 2008 1:52 pm

I'm adding a new field to the ac_ShipMethods table and am trying to get it to display in the admin where you view the shipmethods. Here is what I have so far. It doesn't break the page, but it doesn't do anything either.
How can I get it to show the value in the table for each ShipMethodID? I knew how to do it in 5.5, but it's more complicated in 7 - at least to me it is,working around the .net display controls.

//w2m jme 120408 add indicator for special shipping restrictions
private int _Indicator;
public int Indicator
{
get { return _Indicator; }
}

protected void GetIndicator(int shipMethodId)
{
Microsoft.Practices.EnterpriseLibrary.Data.Database database = Token.Instance.Database;
//GET THE CURRENT W2M INDICATOR FOR THAT SHIPPING METHOD
DbCommand selectCommand = database.GetSqlStringCommand("SELECT w2m_Indicator FROM ac_ShipMethods WHERE ShipMethodId = @shipMethodId");
database.AddInParameter(selectCommand, "@shipMethodId", DbType.Int32, shipMethodId);
int Indicator = (int)database.ExecuteScalar(selectCommand);
//set default value of 1
if (Indicator == null) Indicator = 1;

}

Thanks
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
nickc
Captain (CAPT)
Captain (CAPT)
Posts: 276
Joined: Thu Nov 29, 2007 3:48 pm

Re: New field in database table

Post by nickc » Fri Dec 05, 2008 11:16 am

Are you modifying /Admin/Shipping/Methods/Default.aspx?

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

Re: New field in database table

Post by jmestep » Fri Dec 05, 2008 12:48 pm

Yes, I was trying. I gave up and went to each edit shipmeth page in admin where the other changes are made, which I would have had to do anyway to edit the custom field. I've got that working, but it would be nice to display the new field on the Default.aspx.
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: New field in database table

Post by mazhar » Sat Dec 06, 2008 4:33 am

The problem seems to be in the GetIndicator method try following code

Code: Select all

protected void GetIndicator(int shipMethodId)
    {
        Microsoft.Practices.EnterpriseLibrary.Data.Database database = Token.Instance.Database;
        //GET THE CURRENT W2M INDICATOR FOR THAT SHIPPING METHOD
        DbCommand selectCommand = database.GetSqlStringCommand("SELECT w2m_Indicator FROM ac_ShipMethods WHERE ShipMethodId = @shipMethodId");
        database.AddInParameter(selectCommand, "@shipMethodId", DbType.Int32, shipMethodId);
        int indicator = (int)database.ExecuteScalar(selectCommand);
        //set default value of 1
        if (indicator == null) indicator = 1;
        _Indicator = indicator;
    }

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

Re: New field in database table

Post by jmestep » Sat Dec 06, 2008 10:19 am

How would I put that into a new field added to the Gridview? I don't think it's part of the dataitem?
I've tried all kinds of variations of this: _indicator, Indicator, indicator Eval = etc.
<asp:TemplateField HeaderText="Ind">
<ItemTemplate>
<% =Indicator %>
</ItemTemplate>
</asp:TemplateField>
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
jmestep
AbleCommerce Angel
Posts: 8164
Joined: Sun Feb 29, 2004 8:04 pm
Location: Dayton, OH
Contact:

Re: New field in database table

Post by jmestep » Sat Dec 06, 2008 11:08 am

Mazhar, on your code I get an invalid cast and debugger shows
Warning 5 The result of the expression is always 'false' since a value of type 'int' is never equal to 'null' of type 'int?'
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: New field in database table

Post by mazhar » Thu Dec 11, 2008 1:51 am

Mazhar, on your code I get an invalid cast and debugger shows
Warning 5 The result of the expression is always 'false' since a value of type 'int' is never equal to 'null' of type 'int?'
oops! It seems that its due to following code
//set default value of 1
if (indicator == null) indicator = 1;
Just replace this part of code with something like

Code: Select all

//set default value of 1
        if (indicator == 0) indicator = 1;

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

Re: New field in database table

Post by mazhar » Thu Dec 11, 2008 2:02 am

How would I put that into a new field added to the Gridview? I don't think it's part of the dataitem?
I've tried all kinds of variations of this: _indicator, Indicator, indicator Eval = etc.
<asp:TemplateField HeaderText="Ind">
<ItemTemplate>
<% =Indicator %>
</ItemTemplate>
</asp:TemplateField>
Yes its not the part of dataitem. Better you change the return type of your GetIndicator function to int and return the indicator value. Then you can call it by providing it the shipMethodId to print the desired indicator as below.

Code: Select all

<% GetIndicator(some shipmethod Id here)%>

Post Reply