我被困十进制和我的SQL

时间:2018-01-03 13:27:14

标签: c# mysql database

例如:当我从文本框(txtMaterialUnitPrice,txtPurchasedWeight)输入十进制数字时,如4.5和6.5,总价格应该是29.25但它来自29.这是我的代码。

 salesTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
 materialPrice = decimal.Parse(txtMaterialUnitPrice.Text);
 purchasedWeight = decimal.Parse(txtPurchasedWeight.Text);
 totalPrice = materialPrice * purchasedWeight;

 curSales = Sales.Insert(customerID, customerNameSurname, customerPlate, materialID, 
 materialType, materialPrice, purchasedWeight, totalPrice, salesTime, txtExplanation.Text);

这是插入部分。

 public static Sales Insert(int cID, String cNameSurname, String cPlate, int mID, String mName, Decimal mPrice, Decimal pWeight, Decimal totalPrice, String dt, String explanation)
 {
    String query = string.Format("INSERT INTO sales(CustomerID,CustomerNameSurname,CustomerPlate,MaterialID,MaterialType,MaterialPrice,PurchasedWeight,TotalPrice,SalesDate,Explanation) VALUES ('{0}', '{1}' , '{2}', '{3}','{4}','{5}','{6}','{7}','{8}','{9}')", cID, cNameSurname, cPlate, mID, mName, mPrice, pWeight, totalPrice, dt, explanation);

    MySqlCommand cmd = new MySqlCommand(query, DB.dbConn);

    DB.dbConn.Open();

    cmd.ExecuteNonQuery();

    int id = (int)cmd.LastInsertedId;

    Sales sale = new Sales(id, cID, cNameSurname, cPlate, mID, mName, mPrice, pWeight, totalPrice, dt, explanation);

    DB.dbConn.Close();

    return sale;
  }

Sales Table

0 个答案:

没有答案