数据类型Money C#

队长

有人请帮我,我不知道为什么!

例如,当我在3469,2SQL Server数据库中插入一个值时,我得到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();
    }
谢尔盖·卡里尼琴科(Sergey Kalinichenko)

根据Microsoft类型映射指南,SQL Server的Money类型decimal在C#中被映射到

注意:进行查询的一种正确方法是使用参数,如下所示:

decimal prix = (decimal)(Qte * prixvente);
decimal prix_ttc = prix * (1 + (tva/ 100M));

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.Parameters.Add("@qte", qte);
command.Parameters.Add("@prix", prix);
... // Set other parameters here
command.ExecuteNonQuery();

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章