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

  • 相关阅读:
    每天一个linux命令(9):touch
    每天一个linux命令(8):rm
    每天一个linux命令(7):mv
    每天一个linux命令(6):cp
    每天一个linux命令(5):rmdir
    每天一个linux命令(4):mkdir
    区块链技术与应用——BTC挖矿难度
    区块链技术与应用——BTC网络工作原理
    区块链技术与应用——BTC系统实现
    区块链技术与应用——BTC的共识协议
  • 原文地址:https://www.cnblogs.com/zgqys1980/p/411762.html
Copyright © 2011-2022 走看看