曹永思

导航

Asp.net 修改已有数据的DataTable中某列的数据类型

 DataTable dt_PI = new DataTable();
                    //克隆表结构
                    dt_PI = ds.Tables[0].Clone();

                    dt_PI.Columns["FLTFullPercentage"].DataType = typeof(String);//修改【满柜百分比】列的数据类型

                    foreach (DataRow row in ds.Tables[0].Rows)
                    {
                        DataRow rowNew = dt_PI.NewRow();

                        foreach (DataColumn col in ds.Tables[0].Columns)
                        {
                            if (col.ColumnName == "FLTFullPercentage")
                            {
                                rowNew["FLTFullPercentage"] = (BaseDBHelper.ConvData.StrToDbl("" + row["FLTFullPercentage"]) * 100).ToString("F3") + "%";
                            }
                            else if (col.ColumnName == "NumFreightMoney")
                            {
                                rowNew[col.ColumnName] = BaseDBHelper.ConvData.StrToDbl("" + row[col.ColumnName]).ToString("F2");
                            }
                            else
                            {
                                rowNew[col.ColumnName] = row[col.ColumnName];
                            }

                        }

                        dt_PI.Rows.Add(rowNew);
                    }
View Code

 

posted on 2014-05-09 16:24  曹永思  阅读(1036)  评论(0编辑  收藏  举报