convert SqlDataReader to DataTable

Posted Kyle0418

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了convert SqlDataReader to DataTable相关的知识,希望对你有一定的参考价值。

public static DataTable ConvertDataReaderToDataTable(SqlDataReader reader)
{
    try
    {
        DataTable objDataTable = new DataTable();
        int intFieldCount = reader.FieldCount;
        for (int intCounter = 0; intCounter < intFieldCount; ++intCounter)
        {
            objDataTable.Columns.Add(reader.GetName(intCounter), reader.GetFieldType(intCounter));
        }
        objDataTable.BeginLoadData();

        object[] objValues = new object[intFieldCount];
        while (reader.Read())
        {
            reader.GetValues(objValues);
            objDataTable.LoadDataRow(objValues, true);
        }
        reader.Close();
        objDataTable.EndLoadData();

        return objDataTable;
    }
    catch (Exception ex)
    {
        throw new Exception("Convert Error!", ex);
    }
}

以上是关于convert SqlDataReader to DataTable的主要内容,如果未能解决你的问题,请参考以下文章

Convert Sorted Array to Binary Search Tree & Convert Sorted List to Binary Search Tree

机器视觉 convert_vector_to_tuple算子

How to Convert OST to PST

机器视觉 convert_tuple_to_vector_1d算子

Program to Convert Binary to Decimal

Convert jupyter notebooks to python files