c# - 如何将数据集中的值添加到列表中?

标签 c# asp.net linq ado.net

string str = "Select bd_id from [Active]";
ds = new DataSet(str);
da = new SqlDataAdapter(str, con);
da.Fill(ds);

我想添加我得到的数据集,它是表单中的 ID 列表:

bd_id
   1
   2
   3

作为项目进入通用 LIST

我该怎么做呢?

最佳答案

使用 LINQ to DATATABLE 可以轻松完成任务。

DataTable dtDetails = ds.Table[0];
List<int> lstExcelCurrencyCode =
                    (from dr in dtDetails.AsEnumerable()
                      select  dr.Field<int>("bd_id")).ToList<int>();

关于c# - 如何将数据集中的值添加到列表中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9138874/

相关文章:

c# - 使用 ldap 照片的 ASN.1 包装器创建 G3 传真图像

c# - 使用 linq 从列表中删除项目

linq - 从 LINQ 中的字符串列表生成 CSV

c# - 当 DropDownList Filter 的值不是 ALL 时,如何删除 GridView 中的整个第一列?

asp.net - ASP.NET MVC 应用程序如何严重依赖 System.Web 程序集?

javascript - 将记录添加到数据库时更新转发器

c# - 使用特定字符串从 List<string> 中删除所有内容

c# - 多线程错误 : There is already an open DataReader associated with this Connection which must be closed first

c# - 如何从C#中的StringCollection中删除重复项?

C# 装饰器——接口(interface)还是抽象类?