#region 将DataReader转换为DataTable   
    /// <summary>
    /// 将?DataReader转a换?为aDataTable
    /// </summary>
    /// <param name="reader"></param>
    /// <returns></returns>
    public static DataTable ConvertDataReaderToDataTable(IDataReader reader)
    {
        DataTable objDataTable = new DataTable();
        objDataTable.TableName = "NewTable";
        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;
    }
    #endregion

 
posted on 2012-03-16 11:49  易成波  阅读(713)  评论(0编辑  收藏  举报