Conversion problem SqlDBType.Decimal -> T-SqlType Decimal (12,6)

P

P@rick

Hi all,

I want to call a stored procedure containing a decimal parameter:

SqlCommand dbCommand = new SqlCommand("myStoredProcedure", myConnection);
dbCommand.CommandType = CommandType.StoredProcedure;
SqlParameter parmTOHighShort = dbCommand.Parameters.Add("@dTOHighShort", SqlDbType.Decimal, 9);
parmTOHighShort.Direction = ParameterDirection.Input;
parmTOHighShort.Value = dataObject.TOHighShort;
try
{
dbCommand.ExecuteNonQuery();
}
catch (Exception e)
{
int i = 0;
}

in the stored procedure this parameter is specified as follows:

CREATE PROCEDURE dbo.[myStoredProcedure]( @dTOHighShort AS DECIMAL (12,9) )

AS

.....

this does not work because the SqlDBType.Decimal do not specify any precision, but the T-Sql data type does!

Do any one know how to solve this problem ?

Regards,
P@rick
 
F

Frans Bouma [C# MVP]

P@rick said:
I want to call a stored procedure containing a decimal parameter:

SqlCommand dbCommand = new SqlCommand("myStoredProcedure", myConnection);
dbCommand.CommandType = CommandType.StoredProcedure;
SqlParameter parmTOHighShort = dbCommand.Parameters.Add("@dTOHighShort",
SqlDbType.Decimal, 9);

You didn't set the precision, you set the size to 9, but the precision is
12, and the scale is 9. so yo have to add:
paramTOHighShort.Precision = 12;
paramTOHighShort.Scale = 9;

FB



parmTOHighShort.Direction = ParameterDirection.Input;
parmTOHighShort.Value = dataObject.TOHighShort;
try
{
dbCommand.ExecuteNonQuery();
}
catch (Exception e)
{
int i = 0;
}

in the stored procedure this parameter is specified as follows:

CREATE PROCEDURE dbo.[myStoredProcedure]( @dTOHighShort AS DECIMAL (12,9) )

AS

....

this does not work because the SqlDBType.Decimal do not specify any
precision, but the T-Sql data type does!

Do any one know how to solve this problem ?

Regards,
P@rick
 
P

P@rick

thanxx, it works!

Regards,
P@rick


Frans Bouma said:
P@rick said:
I want to call a stored procedure containing a decimal parameter:

SqlCommand dbCommand = new SqlCommand("myStoredProcedure", myConnection);
dbCommand.CommandType = CommandType.StoredProcedure;
SqlParameter parmTOHighShort = dbCommand.Parameters.Add("@dTOHighShort",
SqlDbType.Decimal, 9);

You didn't set the precision, you set the size to 9, but the precision is
12, and the scale is 9. so yo have to add:
paramTOHighShort.Precision = 12;
paramTOHighShort.Scale = 9;

FB



parmTOHighShort.Direction = ParameterDirection.Input;
parmTOHighShort.Value = dataObject.TOHighShort;
try
{
dbCommand.ExecuteNonQuery();
}
catch (Exception e)
{
int i = 0;
}

in the stored procedure this parameter is specified as follows:

CREATE PROCEDURE dbo.[myStoredProcedure]( @dTOHighShort AS DECIMAL (12,9) )

AS

....

this does not work because the SqlDBType.Decimal do not specify any
precision, but the T-Sql data type does!

Do any one know how to solve this problem ?

Regards,
P@rick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top