【发布时间】:2012-12-17 18:17:54
【问题描述】:
我有一个带有“Products”表的 MySQL 数据库。 “Products”中的一列称为“Price”,数据类型为“double”。
我需要从该列中检索值,因此我创建了一个阅读器等:
MySQLCommand cmd = new MySQLCommand("SELECT Price FROM Products", connection);
MySQLDataReader reader = cmd.ExecuteReaderEx();
if (reader.HasRows == true)
{
while (reader.Read() == true)
{
price = reader["Price"]).ToString();
}
}
问题是价格未设置为预期值。如果数据库中的值为“299.95”,则价格设置为“29995.0”。
知道为什么会这样吗?可以做些什么来解决它?
【问题讨论】:
-
off topic 一般价格表示
decimal,但您似乎将其维护为string -
查看数据库时,值真的是
299.95吗?
标签: c# mysql double datareader