使用WPF / C# / IList接口访问Oracle查询数据
我正在用 C# 重写 IronPython WPF 应用程序(出于各种原因)。在 IPython 中,我可以这样做:
rows = dt.GetList()
foreach (row in rows);
ln = row["lastname"] ... etc.
等等。由于 C# 对数据类型更加挑剔,我无法弄清楚如何让 foreach 之类的东西工作,甚至无法让普通索引版本(在下面的 MessageBox 中)工作。我还没有到要把它变成 CollectionView 的地步。已经在谷歌上搜索了大量关于如何做比这更复杂的事情的信息 - 我最终可能想这样做 - 但现在,只是想看看我是否可以将我的数据恢复为简单的类似 Oracle 的数据类型- 字符串、整数等。建议表示赞赏。
OracleDataAdapter da = new OracleDataAdapter(sql, db_connection);
DataTable dt = new DataTable();
da.Fill(dt);
System.Collections.IList rows = ((IListSource)dt).GetList();
MessageBox.Show(rows[0]["lastname"]);
I'm rewriting an IronPython WPF app in C# (for assorted reasons). In IPython, I can just do something like:
rows = dt.GetList()
foreach (row in rows);
ln = row["lastname"] ... etc.
and so forth. Since C# is a lot more picky about data types, I haven't been able to figure out how to get something like the foreach to work, or even to get the plain indexed version (in the MessageBox below) to work. I'm not to the point where I want to turn it into a CollectionView. Have googled up quite a bit of info on how to do something a lot more complex than this - I may want to do that eventually - but for now, just trying to see if I can get my data back into simple Oracle-like data types - strings, Ints, etc. Suggestions appreciated.
OracleDataAdapter da = new OracleDataAdapter(sql, db_connection);
DataTable dt = new DataTable();
da.Fill(dt);
System.Collections.IList rows = ((IListSource)dt).GetList();
MessageBox.Show(rows[0]["lastname"]);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不必转换数据表,已经有一个数据行列表。
使用 foreach 循环:
您还可以使用以下方式访问:
打印整个表格:
使用 col.DataType,您可以检索类型;)
希望它会有所帮助
you don't have to convert your datatable, there is already a list of datarow.
With a foreach loop :
You can also access with :
To print the whole table :
With col.DataType, you can retrieve the type ;)
Hope it will help