我如何循环遍历 OracleDataReader 的所有列
我有以下代码,我想循环遍历此查询结果中的所有字段并填充名为 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();
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();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
GetSchemaTable 将返回很多有关列的信息,包括它们的名称以及大小、类型等。
我假设您希望字典的键是列名称,值是行值。如果是这样,这应该有效:
您还可以使用 GetValues() 获取列数,并调用 GetName(int) 对于每个。
GetSchemaTable will return a lot of information about the columns, including their name but also size, type, etc.
I presume you want the key of the dictionary to be the column name, and the value to be the row value. If so, this should work:
You could also use GetValues() to get the number of columns, and call GetName(int) for each.
你应该能够做这样的事情:
You should be able to do something like this: