zoukankan      html  css  js  c++  java
  • asp.net将DataView转换成DataTable

    这个比较简单
     /// <summary>
        
    /// 将DataView转换为DataTable
        
    /// </summary>
        
    /// <param name="obDataView"></param>
        
    /// <returns></returns>

        public DataTable GetDataTable(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;
        }
  • 相关阅读:
    configuring express for ejs
    if else in EJS
    nodegroupchat exercise
    heap&stack 区别
    如何构建积木式Web应用(引自微软CSDN )
    Configuring IIS: Mapping .* to the aspnet_isapi.dll
    递归遍历XML生成树
    数据库应用:无法更新到数据库
    C#中HashTable的用法
    如何使用Eclipse编译C,C++,JAVA程序
  • 原文地址:https://www.cnblogs.com/ringwang/p/1054255.html
Copyright © 2011-2022 走看看