我有以下代码,我想循环遍历此查询结果中的所有字段并填充名为 field 的字典。
给定一个数据读取器,这可能吗?
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();
你应该能够做这样的事情:
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 );
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)