我如何从数据表中获取某些特定值?

编程入门 行业动态 更新时间:2024-10-10 03:24:45
本文介绍了我如何从数据表中获取某些特定值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有ds中的数据,我想填写数据表 之后,我想从该表中只取特定的行,这样我怎么做呢?????? /> 我的尝试:

i have data in ds and i want to fill in data table after that i want to take only particular row from that table so how i can do that?????? What I have tried:

oBuyerBO.Ds.Tables.Add(dt); foreach (DataRow row in dt.Rows) { if (row["CompanyID"].ToString() != hidSelectedSupplier.ClientID) { return row["CompanyName"]; } }

推荐答案

至少 - 很少有办法实现这一目标...... 1)使用Linq: There's - at least - few ways to achieve that... 1) using Linq: //returns the list of rows which meet some criteria var resultRow = dt.AsEnumerable() .Where(x => x.Field<int>("CompanyID") != hidSelectedSupplier.ClientID) .ToList();</int>

2)使用Filter ans选择方法: 如何:直接在数据表中筛选和排序 [ ^ ] 试试!

2) using Filter ans Select methods: How to: Filter and Sort Directly in Data Tables[^] Try!

您应该使用DataTable对象的Select()方法,如下所示。 Hi, You should use Select() method of the DataTable object like shown below. string filterCondition = string.format(CultureInfo.CurrentCulture, "{0} = '{1}'", "CompanyName", "Test"); // assuming that you have a column called CompanyName in the DataTable and you are searching for the rows where CompanyName = "Test" DataRow[] selectedRows = dt.Select(filterCondition); foreach(DataRow rowItem in selectedRows) { // Do your stuff }

如果您正在寻找,请告诉我。 谢谢, Debasis。

Please let me know if this is what you are looking for. Thanks, Debasis.

dt = oBuyerBO.Ds.Tables[0]; foreach (DataRow row in dt.Rows) { if (oCompanyBO.SelectedSupplierIDs.ToString() != row["CompanyID"].ToString()) { lstSelectedSuppliers.Value= row["CompanyName"].ToString(); } }

i我正在尝试这个 但是此代码不检查if条件 i想要显示不在oCompanyBO.SelectedSupplierIDs中的值 ...

i am trying this but this code do not check the if condition i want to display the value which is not in the oCompanyBO.SelectedSupplierIDs ...

更多推荐

我如何从数据表中获取某些特定值?

本文发布于:2023-11-05 03:00:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1559727.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据表   定值

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!