.NET - How do I retrieve specific items out of a Dataset?(.NET - 如何从数据集中检索特定项目?)
问题描述
我有以下代码连接到数据库并将数据存储到数据集中.
I have the following code which connects to a database and stores the data into a dataset.
我现在需要做的是从数据集中获取一个值(实际上它是第一行第 4 列和第 5 列的两个值)
What I need to do now is get a single value from the data set (well actually its two the first row column 4 and 5)
OdbcConnection conn = new OdbcConnection();
conn.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString2"].ConnectionString;
DataSet ds = new DataSet();
OdbcDataAdapter da = new OdbcDataAdapter("SELECT * FROM MTD_FIGURE_VIEW1", conn);
da.Fill(ds)
所以,我需要获取两个特定项目并将它们存储到整数中,伪代码将是
So, I need to get two specific items and store them into ints, the psudo code would be
int var1 = ds.row1.column4
int var2 = ds.row1.column5
关于如何做到这一点的任何想法?
Any ideas on how I can do this?
另外,有人能否解释一下数据表,因为这可能与我将如何做这件事有关.
Also, can some one shed a light on data tables too as this may be related to how I'm going about doing this.
推荐答案
你可以这样做...
如果您想使用 ColumnName
Int32 First = Convert.ToInt32(ds.Tables[0].Rows[0]["column4Name"].ToString());
Int32 Second = Convert.ToInt32(ds.Tables[0].Rows[0]["column5Name"].ToString());
或者,如果你想使用 Index
Int32 First = Convert.ToInt32(ds.Tables[0].Rows[0][4].ToString());
Int32 Second = Convert.ToInt32(ds.Tables[0].Rows[0][5].ToString());
这篇关于.NET - 如何从数据集中检索特定项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:.NET - 如何从数据集中检索特定项目?


基础教程推荐
- 全局 ASAX - 获取服务器名称 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01