Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I using the code for price column

C# code: 
sku.SKUPrice = ValidationHelper.GetDecimal(txtActualPrice.Text, default(decimal));

The value is binding the textbox is "0.000000000"

I need the output is "0.00" only.

The database column datatype is "decimal(18.9)"

If I run the "
alter table COM_SKU alter Column SKUPrice decimal(18,2) not null" query I am getting below error message.


Msg 5074, Level 16, State 1, Line 5
The index 'IX_COM_SKU_SKUPrice' is dependent on column 'SKUPrice'.
Msg 4922, Level 16, State 9, Line 5
ALTER TABLE ALTER COLUMN SKUPrice failed because one or more objects access this column.


<pre>   <cms:CMSTextBox ID="txtActualPrice" runat="server" EnableViewState="false" CssClass="input__text"></cms:CMSTextBox>
                    <asp:RequiredFieldValidator ID="rfvActualPrice" runat="server" CssClass="EditingFormErrorLabel" ControlToValidate="txtActualPrice"></asp:RequiredFieldValidator>
                    <asp:RegularExpressionValidator ID="revActualPrice" runat="server" CssClass="EditingFormErrorLabel"
                        ControlToValidate="txtActualPrice" ValidationExpression="((\d+)((\.\d{1,100})?))$">
                    </asp:RegularExpressionValidator>


What I have tried:

<pre>   <cms:CMSTextBox ID="txtActualPrice" runat="server" EnableViewState="false" CssClass="input__text"></cms:CMSTextBox>
                    <asp:RequiredFieldValidator ID="rfvActualPrice" runat="server" CssClass="EditingFormErrorLabel" ControlToValidate="txtActualPrice"></asp:RequiredFieldValidator>
                    <asp:RegularExpressionValidator ID="revActualPrice" runat="server" CssClass="EditingFormErrorLabel"
                        ControlToValidate="txtActualPrice" ValidationExpression="((\d+)((\.\d{1,100})?))$">
                    </asp:RegularExpressionValidator>
Posted
Updated 10-Dec-19 7:42am
Comments
Richard MacCutchan 9-Dec-19 7:03am    
The message is telling you that you cannot alter that column because it is linked to an index. You need to remove the index and try again.
Ashutosh Gpta 9-Dec-19 7:11am    
if it is just two decimal value then solution is to use string.format to convert into max two decimal. e.g. sku.SKUPrice = string.Format("{0:0.##}", txtActualPrice.Text);
but it seems you have indexing issue as mentioned by Richard above.

1 solution

The error message is not related to the subject of "trailing zeros".

I'd suggest to read this: ALTER TABLE ALTER COLUMN [access-id] failed because one or more objects access this column[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900