如何将C#float保存到Mysql float?

时间:2017-06-06 20:50:26

标签: c# mysql

我找不到任何解决方案,如何将c#中的浮点数保存到mysql中。它只保存整数。 如果我的浮动是例如2.5并且我将它保存到我的表中,那么它就是2。

我将类型更改为double,但我得到了相同的结果。 有人可以帮帮我吗?

2 个答案:

答案 0 :(得分:0)

你可以使用

的类型
DECIMAL

您可以获得一些信息this

答案 1 :(得分: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