• Framework1.1 DataView 转DataTable


    因为Framework2.0开始DataView 有toTable()方法,可以直接转。但vs2003还是Framework1.1 没有这个方法。

    所以要手动转,方法如下:

    public static DataTable CreateTable(DataView obDataView)
            {
                if (null == obDataView)
                {
                    throw new ArgumentNullException("DataView", "Invalid DataView object specified");
                }
                DataTable obNewDt = obDataView.Table.Clone();
                int idx = 0;
                string[] strColNames = new string[obNewDt.Columns.Count];
                foreach (DataColumn col in obNewDt.Columns)
                {
                    strColNames[idx++] = col.ColumnName;
                }
                IEnumerator viewEnumerator = obDataView.GetEnumerator();
                while (viewEnumerator.MoveNext())
                {
                    DataRowView drv = (DataRowView)viewEnumerator.Current;
                    DataRow dr = obNewDt.NewRow();
                    try
                    {
                        foreach (string strName in strColNames)
                        {
                            dr[strName] = drv[strName];
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    obNewDt.Rows.Add(dr);
                }
                return obNewDt;
            } 

  • 相关阅读:
    Maven 打包指定子工程项目(springcloud分模块打包)
    linux常见问题: zip/unzip: command not found
    CentOS8安装jdk1.8
    nacos-docker镜像安装nacos并配置数据库
    浏览器的一个请求从发送到返回都经历了什么
    python之scrapy
    常见的爬虫与反爬虫斗争
    Python闭包与延迟绑定
    ip代理
    python编程:统计文件中单词出现次数
  • 原文地址:https://www.cnblogs.com/andycai/p/2376192.html
Copyright © 2020-2023  润新知