2017-06-06 59 views
-2

我找不到任何解决方案,如何将c#中的float保存到mysql中。它只保存整数。 如果我的浮球是例如2.5,我将它保存到我的表中,比它有一个2.如何将C#float保存到Mysql float?

我改变了类型为双倍,但我得到了相同的结果。 有人能帮助我吗?

+5

什么你的查询看起来像什么?你在使用参数吗?显示一些代码! – itsme86

+3

列定义是什么样的? – mjw

回答

0

可以使用的

DECIMAL 

的一些信息类型,你可以得到this

0

这是我的SQL命令:

using (MySqlConnection connection = new MySqlConnection(sqlConnString.GetConnectionString(true))) 
     { 
      connection.Open(); 

      string SQLString = @"INSERT INTO account_components 
           (accountID,shapeMother,shapeFather,skinMother,skinFather,shapeMix,skinMix, 
           eyeColor,eyeBrows,lipstick,lipstickColor,beard,beardColor, 
           hair,hairColor) VALUES 
           ('" + _acc.Id + "'," + 
           "'" + _acc.Character.ShapeMother + "'," + 
           "'" + _acc.Character.ShapeFather + "'," + 
           "'" + _acc.Character.SkinMother + "'," + 
           "'" + _acc.Character.SkinFather + "'," + 
           "'@ShapeMix'," + 
           "'@SkinMix'," + 
           "'" + _acc.Character.EyeColor + "'," + 
           "'" + _acc.Character.EyeBrows + "'," + 
           "'" + _acc.Character.Lipstick + "'," + 
           "'" + _acc.Character.LipstickColor + "'," + 
           "'" + _acc.Character.Beard + "'," + 
           "'" + _acc.Character.BeardColor + "'," + 
           "'" + _acc.Character.Hair + "'," + 
           "'" + _acc.Character.HairColor + "')"; 

      using (MySqlCommand cmd = new MySqlCommand(SQLString, connection)) 
      { 
       cmd.Parameters.Add("ShapeMix", MySqlDbType.Float).Value = 0.5f; //_acc.Character.ShapeMix; 
       cmd.Parameters.Add("SkinMix", MySqlDbType.Float).Value = 0.5f; //_acc.Character.SkinMix; 
       cmd.ExecuteNonQuery(); 
      } 

     } //connection closed and disposed here 
    } 

这是我的数据库:Database Description