我如何遍历OracleDataReader的所有列 [英] how can i loop through all of the columns of the OracleDataReader

查看:75
本文介绍了我如何遍历OracleDataReader的所有列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,我想遍历查询结果中的所有字段并填充名为field的字典.

I have the following code and i want to loop through all the fields in the result of this query and populate the dictionary called field.

有可能提供数据读取器吗?

Given a datareader is this possible?

            OracleCommand command = connection.CreateCommand();
            string sql = "Select * from MYTABLE where ID = " + id;
            command.CommandText = sql;

            Dictionary<string, string> fields = new Dictionary<string, string>();
            OracleDataReader reader = command.ExecuteReader();

推荐答案

您应该可以执行以下操作:

You should be able to do something like this:

Dictionary<string, string> fields = new Dictionary<string, string>();
OracleDataReader reader = command.ExecuteReader();

if( reader.HasRows )
{
    for( int index = 0; index < reader.FieldCount; index ++ )
    {
        fields[ reader.GetName( index ) ] = reader.GetString( index );
    }    
}

这篇关于我如何遍历OracleDataReader的所有列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆