我有以下代码,我想遍历此查询结果中的所有字段并填充名为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 ); } }