使用C#/ ASP.NET将十进制保存到SQL Server数据库

时间:2017-07-10 15:54:00

标签: c# sql asp.net

我正在处理库存应用程序,我正在尝试存储" premium"的小数。我们在拍卖时采购某些商品时付款。通过下拉列表选择百分比,将其发送到ASMX Web服务,然后使用SQL Server存储过程插入到数据库中。

似乎所有内容都传递给SQL Server存储过程,但该值存储为" 0"每次。我尝试过的值是.15,.25和.35。该列在SQL Server中设置为decimal(18,0)

这是我的网络方法:

public string TestMethod(string SupplierName, string SupplierType, string SupplierLocation, decimal SupplierPremium)
{
    string _supplierName = SupplierName;
    string _supplierType = SupplierType;
    decimal _supplierPremium = Convert.ToDecimal(SupplierPremium);
    string _supplierLocation = SupplierLocation;

    // Database Connection
    using(SqlConnection myConnection = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]))
    {
        using (SqlCommand myCommand = new SqlCommand("InsertSupplier",myConnection))
        {
            myCommand.CommandType = CommandType.StoredProcedure;
            myCommand.Parameters.Add(new SqlParameter("SupplierName",_supplierName));
            myCommand.Parameters.Add(new SqlParameter("SupplierType", _supplierType));
            myCommand.Parameters.Add(new SqlParameter("SupplierPremium", _supplierPremium));
            myCommand.Parameters.Add(new SqlParameter("SupplierLocation", _supplierLocation));

            myConnection.Open();
            myCommand.ExecuteNonQuery();
        }
    }
}

0 个答案:

没有答案