存储过程如下:
CREATE PROCEDURE p1 @UserID VARCHAR(20),
 @TotalScore decimal(9,1) out,
 @ExpertNumber int out,
 @AverageScore decimal(9,1)  out,
 @OrderID INT out,
 @Score INT out ,
 @ValidScore decimal(9,1) out AS
set @UserID='yangtanyu'
declare @groupID INT
declare @number int
set @TotalScore=283.3
set @ExpertNumber=0.0
set @AverageScore=45.9
set @Score=100
set @ValidScore=28.9
set @OrderID=1代码如下:
SqlConnection conn = null;
conn = new SqlConnection("Server=127.0.0.1;User ID=sa;Password=t30;Initial Catalog=ETA"); SqlParameter[] parameters = {
new SqlParameter("@UserID", SqlDbType.VarChar, 20),
new SqlParameter("@TotalScore", SqlDbType.Decimal,8),
new SqlParameter("@ExpertNumber", SqlDbType.Int, 4),
new SqlParameter("@AverageScore", SqlDbType.Decimal,8),
new SqlParameter("@OrderID", SqlDbType.Int, 4),
new SqlParameter("@Score", SqlDbType.Int,4),
new SqlParameter("@ValidScore", SqlDbType.Decimal,8)
};

// set the values
parameters[0].Value = "yangtanyu";
parameters[1].Direction = ParameterDirection.Output;
parameters[2].Direction = ParameterDirection.Output;
parameters[3].Direction = ParameterDirection.Output;
parameters[4].Direction = ParameterDirection.Output;
parameters[5].Direction = ParameterDirection.Output;
parameters[6].Direction = ParameterDirection.Output;
ArrayList arrayList = new ArrayList();
try
{
conn.Open();
SqlHelper.ExecuteNonQuery(conn,CommandType.StoredProcedure,"p1",parameters);
for(int i=1;i<7;i++)
{

 Response.Write(parameters[i].Value.ToString());
 Response.Write("<br>");
}
            
// arrayList.Add(parameters[1].Value);
// arrayList.Add(parameters[2].Value);
// arrayList.Add(parameters[3].Value);
// arrayList.Add(parameters[4].Value);
// arrayList.Add(parameters[5].Value);
// arrayList.Add(parameters[6].Value);
}
catch(SqlException ex)
{
throw ex;
}
finally
{
if(conn != null)
conn.Dispose();
}
//
// for(int i=0;i<6;i++)
// {
//
//  Response.Write(arrayList[i].ToString());
//  Response.Write("<br>");
// }输出参数得到如下结果:没有了1位小数?为什么?请高人指点!283
0
46
1
100
29

解决方案 »

  1.   

    楼主参看:http://community.csdn.net/Expert/TopicView3.asp?id=4870863
      

  2.   

    你的参数需要指定小数:SqlParameter workParam = command.Parameters.Add("@moneypay", SqlDbType.Decimal);
    workParam.Precision=18;  //整数位
    parameter.Scale = 2;     //小数位
      

  3.   

    更正:
    SqlParameter workParam = command.Parameters.Add("@moneypay", SqlDbType.Decimal);
    workParam.Precision=18; //整数位
    workParam.Scale = 2; //小数位