c# – 从DataSet获取值到变量中

我有以下方法返回数据集.我使用的是.NET 2.0
DataSet ds = GetAllRecords();

我想从特定行的每列中获取值并将其绑定到变量.
怎么能实现这一目标?

目前该方法返回表中的所有行,我必须根据ID找到该特定行.

但是,如果那是不可能的,我可以来

DataSet ds = GetSpecificRecord(id);

但我仍然需要从每列获取值并将其绑定到变量.
请指教.

解决方法

// Create a table 
DataTable table = new DataTable("users");
table.Columns.Add(new DataColumn("Id",typeof(int)));
table.Columns.Add(new DataColumn("Name",typeof(string)));

table.Rows.Add(1,"abc");
table.Rows.Add(2,"ddd");
table.Rows.Add(3,"fff");
table.Rows.Add(4,"hhh d");
table.Rows.Add(5,"hkf ds");

// Search for given id e.g here 1

DaTarow[] result = table.Select("Id = 1"); // this will return one row for above data 
foreach (DaTarow row in result)
{
    Console.WriteLine("{0},{1}",row[0],row[1]);
}

相关文章

C#项目进行IIS部署过程中报错及其一般解决方案_c#iis执行语句...
微信扫码登录PC端网站应用的案例(C#)_c# 微信扫码登录
原文地址:http://msdn.microsoft.com/en-us/magazine/cc163...
前言 随着近些年微服务的流行,有越来越多的开发者和团队所采...
最近因为比较忙,好久没有写博客了,这篇主要给大家分享一下...
在多核CPU在今天和不久的将来,计算机将拥有更多的内核,Mic...