inserting a decimal number from.net to stored proc. with decimal parameter

I'm trying to enter large number 99999999, (8 digits) converting to decimal in .NET, then using that as a parameter in stored proc. which has a decimal type (decimal(15,2) as a parameter.

C#:

if (txtAnnualizedSaving.Text.Trim() != string.Empty)

{

try

{

sdata.AnnualizedSaving =
Convert.ToDecimal(txtAnnualizedSaving.Text);

// only for testing ....

scale = (System.Decimal.GetBits(sdata.AnnualizedSaving)[3] >> 16) & 31;

}

catch { sdata.AnnualizedSaving = 0; }

}

 

... In the business object I have the following code:

private bool UpdateData()

{

bool ret = false;

try

{

 

System.Nullable<decimal> annualizedSaving = null;if (!data.IsAnnualizedSavingNull())

annualizedSaving = data.AnnualizedSaving;

else annualizedSaving = 0;

// StatusID default value is Proposed(1) as per requirement

adapter.UpdateData(

annualizedSaving );ret = true;

}

catch (Exception e)

{

ErrorEventArg arg = new ErrorEventArg(BUSINESS_OBJECT_NAME, "UpdateData", e, this.AdditionalInformation);

if (BusinessError != null)

BusinessError(this, arg);

}

 The above code is giving an exception "Parameter value '99999999.00' is out of range". If I use only 7 digits i.e. 9999999 it works?

Any help would be appreciated.

 

 

0
aspnetrwa
6/19/2007 7:47:07 PM
asp.net.object-datasource 16182 articles. 0 followers. Follow

6 Replies
834 Views

Similar Articles

[PageSpeed] 17

What is the data type, and size, of the column in the database? 

If it's 'smallmoney', it's not big enough...use 'money'.

 


Steve Wellens

My blog
0
SGWellens
6/19/2007 11:11:25 PM

The size of the data column in SQL 2005 database is decimal(15,2)

0
aspnetrwa
6/20/2007 2:19:31 PM

Hi,

I assume that this exception is because the precision and scale properties are not set properly in the parameter.

If you're using SqlParameter for updating, please use the following code.

    SqlParameter parameter = new SqlParameter("@Price", SqlDbType.Decimal);
    parameter.Value = 99999999.0
    parameter.Precision = 15;
    parameter.Scale = 2;
    command.Parameters.Add(parameter);

If this does not answer your question, please feel free to mark the post as Not Answered and reply. Thank you!


Sincerely,
Kevin Yu
Microsoft Online Community Support

Please remember to click “Mark as Answer” on the post that helps you, and to click “Mark as Not Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
0
Kevin
6/21/2007 5:33:16 AM

Thanks for the reply, I'm using xsd to connect to the Sql storred proc. The properties for the parameter which I'm trying to insert do not have precision and scale attributes in the xsd. The properties for the decimal type just indicate using decimal.

0
aspnetrwa
6/21/2007 4:09:51 PM

Hi,

If you're configuring a TableAdapter to query data, you will be able to set parameter information from the property list.

Here are the steps:

1. Right click on the TableAdapter, and select Properties from the context menu.
2. Find the command where your stored procedure is used. For example, UpdateCommand, just expand UpdateCommand.
3. Click ... on Parameters to activate the Paramters Collection Editor.
4. Select the @Price from left and you will see Precision and Scale on the right.


Sincerely,
Kevin Yu
Microsoft Online Community Support

Please remember to click “Mark as Answer” on the post that helps you, and to click “Mark as Not Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
0
Kevin
6/22/2007 3:46:48 AM

That was it. Once again thanks.

0
aspnetrwa
6/22/2007 2:32:58 PM
Reply: