我有以下代码,我想循环遍历此查询结果中的所有字段,并填充称为字段的字典.
鉴于datareader这可能吗?
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();
Run Code Online (Sandbox Code Playgroud)
Mik*_*att 17
你应该可以做这样的事情:
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 );
}
}
Run Code Online (Sandbox Code Playgroud)