【发布时间】:2014-11-27 13:47:39
【问题描述】:
有人请帮帮我,我不知道为什么!
当我在我的 SQL Server 数据库中插入一个值(例如 3469,2)时,我得到 34692,0000
列的类型为Money,值为double类型
// code
public void updateligne_facture(String Ref, int Qte,String Reffacture,float prixvente,int tva)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = @"Data Source=AKRAM-PC\SQLEXPRESS;Initial Catalog=MM_DataBase;Integrated Security=True";
con.Open();
double prix = Qte * prixvente;
double prix_ttc = prix * (1 + (tva/ 100D));
String requete = "update lc SET lc.Quantite='" + Qte + "',lc.Prix_HT='"+prix+"',lc.Prix_TTC='"+prix_ttc+"' FROM LIGNES_FACTURE as lc JOIN MM_ARTICLE as art ON lc.ID_Article=art.ID JOIN MM_Facture as f ON lc.ID_Facture=f.ID WHERE art.AR_Ref='" + Ref + "' AND f.Ref='" + Reffacture + "'";
SqlCommand command = new SqlCommand(requete, con);
command.ExecuteNonQuery();
con.Close();
}
【问题讨论】:
-
能否请您也出示您的插入代码?
-
在c#中使用小数
-
您应该始终使用parameterized queries。这种字符串连接对SQL Injection 攻击开放。还可以使用
using语句处理您的数据库连接和对象。 -
@Soner Gönül 是的,我将使用参数化查询。但我必须为这个问题做些什么!
-
如果我没记错的话,
decimal是 SQL Server 中优于money的首选数据类型,因为它更加精确和可用:Should you choose the MONEY or DECIMAL(x,y) datatypes in SQL Server?
标签: c# sql sql-server-2008