SqlCommand com 
……
com.Parameters.Add("@Quantity", SqlDbType.Decimal);com.Prepare();这句提示 没有显示的指定Decimal的精度
Prepare()不通过
请问应该怎么写

解决方案 »

  1.   

    com.Parameters.Add("@Quantity", SqlDbType.Decimal(10,2));
    好像是这样子吧,以前做过的,忘了
      

  2.   

    com.Parameters.Add("@Quantity", SqlDbType.Decimal, 10, 2);
    按Ctrl + Shift + 空格显示提示
      

  3.   

    两位的方法都编译错误啊第一个:“System.Data.SqlDbType.Decimal”是“字段”,但此处被当做“方法”来使用第二个:与“System.Data.SqlClient.SqlParameterCollection.Add(string, System.Data.SqlDbType, int, string)”最匹配的重载方法具有一些无效参数
      

  4.   


    如果不调用SqlCommand.Prepare() 方法
    那么com.Parameters.Add("@Quantity", SqlDbType.Decimal); 这样子也是正确的调用的话就是错误:SqlCommand.Prepare方法要求“Decimal”类型的参数具有显式设置的“精度”和“小数位数”。
      

  5.   

    像这个问题不能只通过构造函数来解决了,你需要生成Parameters的实例通过实例来设置精度,比如:
    SqlParameter par = new SqlParameter("@Quantity", SqlDbType.Decimal);
    par.Precision = 18;
    par.Scale = 3;
    com.Parameters.Add(par);