C#使用OracleDataReader返回DataTable

string data = string.Empty;
DataTable OutDataTable = new DataTable();
OracleDataReader daReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
OutDataTable = new DataTable();
DataRow dataRow;

//设置Table名和Column名
OutDataTable.TableName ="test";
for (int j = 0; j < daReader.FieldCount; j++)
{
//获取列名
OutDataTable.Columns.Add(daReader.GetName(j));
}

//循环取数据集合中的数据,存到DataTable中
do
{
while (daReader.Read())
{
dataRow = OutDataTable.NewRow();
for (int j = 0; j < daReader.FieldCount; j++)
{
data = daReader[j].ToString();
dataRow[j] = data;
}
OutDataTable.Rows.Add(dataRow);
}
} while (daReader.NextResult());

dtTemp = OutDataTable;

 

上一篇:File.separator在Linux与windows适用于通配路径


下一篇:c++ 字符串分割写法 一般比较常用 懒得每次都写 记录下