.NET - 如何检索特定的项目从一个数据集的? [英] .NET - How do I retrieve specific items out of a Dataset?

查看:134
本文介绍了.NET - 如何检索特定的项目从一个数据集的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code的数据连接到数据库,并存储到数据集。

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)

所以,我需要得到两个具体项目,并将其存储到整数的psudo code会

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());

或者,如果你想使用访问首页

Int32 First = Convert.ToInt32(ds.Tables[0].Rows[0][4].ToString());
Int32 Second = Convert.ToInt32(ds.Tables[0].Rows[0][5].ToString());

这篇关于.NET - 如何检索特定的项目从一个数据集的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆