数据库 Sqlserver2000 中有一字段类型为Decimal 小数位为2位
语言环境C#/VB.NET
在用DataSet取到数据后在DataTable里只读出被四舍五入后的数据
65.56读出为66
65.42读出为65
请教问题出什么地方?怎么解决?

解决方案 »

  1.   

    不会的!你在XML架构里将此字段的数据类型改为Decimal即可。
      

  2.   

    string.Format("{0:n2}",1234.5678)
      

  3.   

    请贴出填充DataSet的过程,DataTable中的数据类型是否有被修改
      

  4.   

    是啊,在默认的情况下是不会有这种问题的
    除非你取出数据后自己对datatable进行过四舍五入的操作
      

  5.   

    若在SQL Server里是decimal(p,s)类型,65.56。
    使用:DataSet ds = new DataSet();
    通过ADO.NET读到DataSet/DataTable后,数据的值不会发生变化,类型成了object.
    将这些数据读到float/double类型的变量中或string类型的变量中就可以了。若你在创建DataSet/DataTable时:除了用DataSet ds = new DataSet();
    还用了DataTable dt = ds.Tables[0];
    DataColumn dc = dt.Columns.Add("column_name", typeof(int));等转换列类型的代码,
    那么从DataTable中取出的值就会发生变化。
      

  6.   

    疏忽啦,呵呵,查看LIB后发现自己疏忽了很关键的FillSchema所以非常感谢
    wangchen19820203(超人) 
    的提醒。原文如下:
    The SqlDataAdapter class provides two methods, Fill and FillSchema, that are crucial to loading this data. Both of these methods load information into a DataSet. Fill loads the data itself, and FillSchema loads all of the available metadata about a particular table (such as column names, primary keys, and constraints). A good way to handle the data loading is to run FillSchema followed by Fill. For example: