Page 1 of 1
New field in database table
Posted: Thu Dec 04, 2008 1:52 pm
by jmestep
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
Re: New field in database table
Posted: Fri Dec 05, 2008 11:16 am
by nickc
Are you modifying /Admin/Shipping/Methods/Default.aspx?
Re: New field in database table
Posted: Fri Dec 05, 2008 12:48 pm
by jmestep
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.
Re: New field in database table
Posted: Sat Dec 06, 2008 4:33 am
by mazhar
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;
}
Re: New field in database table
Posted: Sat Dec 06, 2008 10:19 am
by jmestep
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>
Re: New field in database table
Posted: Sat Dec 06, 2008 11:08 am
by jmestep
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?'
Re: New field in database table
Posted: Thu Dec 11, 2008 1:51 am
by mazhar
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;
Re: New field in database table
Posted: Thu Dec 11, 2008 2:02 am
by mazhar
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)%>