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

  • Thread starter Thread starter P@rick
  • Start date Start date
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
 
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
 
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
 
Back
Top