zoukankan      html  css  js  c++  java
  • 转换DATAREADER为 dataset dodo

    C#版

    //转换DATAREADER为 dataset
      public static DataTable ConvertDataReaderToDataTable(SqlDataReader reader)
      {
       DataTable objDataTable = new DataTable();

       int intFieldCount = reader.FieldCount ;

       for(int intCounter =0 ;intCounter <= intFieldCount-1; intCounter++)
       {
        objDataTable.Columns.Add(reader.GetName(intCounter),reader.GetFieldType(intCounter));
       }

       //populate datatable
       objDataTable.BeginLoadData();


       //object[] objValues = new object[intFieldCount -1];

        object[] objValues = new object[intFieldCount];

       while (reader.Read())
       {
        reader.GetValues(objValues);

        objDataTable.LoadDataRow(objValues,true);
       }

       reader.Close();

       objDataTable.EndLoadData();

       return objDataTable;


      }

    VB

     ' convert datareader to dataset
            Public Function ConvertDataReaderToDataTable(ByVal reader As IDataReader) As DataTable

                ' create datatable from datareader
                Dim objDataTable As New DataTable
                Dim intFieldCount As Integer = reader.FieldCount
                Dim intCounter As Integer
                For intCounter = 0 To intFieldCount - 1
                    objDataTable.Columns.Add(reader.GetName(intCounter), reader.GetFieldType(intCounter))
                Next intCounter

                ' populate datatable
                objDataTable.BeginLoadData()
                Dim objValues(intFieldCount - 1) As Object
                While reader.Read()
                    reader.GetValues(objValues)
                    objDataTable.LoadDataRow(objValues, True)
                End While
                reader.Close()
                objDataTable.EndLoadData()

                Return objDataTable

            End Function

  • 相关阅读:
    CSP -- 运营商内容劫持(广告)的终结者
    vue学习:解决Apycharm的 * is only available in ES6(use 'esversion: 6') 问题
    nvm、node、npm安装以及pycharm配置eslint
    python中的daemon守护进程实现方法
    python语言基础问题汇总
    python -- DNS处理模块dnspython
    Python ping 模块
    如何把Python脚本导出为exe程序
    从实际案例聊聊Java应用的GC优化
    Python类(六)-静态方法、类方法、属性方法
  • 原文地址:https://www.cnblogs.com/zgqys1980/p/411762.html
Copyright © 2011-2022 走看看