简体   繁体   English

进行数据行Select()查询

[英]Making a datarow Select() Query

The thing is i have a data row array which contains ID and parent id as its fields. 事情是我有一个数据行数组,其中包含ID和父ID作为其字段。

I have used the following code and it returned the correct values , 我使用了以下代码,它返回了正确的值,

datarow [] dt = datarow.select("  Parent = '0' ");

I want to select only those rows which don't have the '0' as its Parent.I know sql i am not getting how the select function works. 我只想选择那些不具有“ 0”作为其Parent.I的行。我知道SQL我不知道select函数的工作方式。

Try using LINQ - Here is an example to use, I think this is what you wanted: 尝试使用LINQ-这是一个示例,我想这就是您想要的:

  DataTable dt = new DataTable("Example");
  dt.Columns.Add("ID", typeof(int));
  dt.Columns.Add("ParentID", typeof(int));
  dt.Rows.Add(1, 0);
  dt.Rows.Add(1, 1);

  var equal0 = dt.Rows.Cast<DataRow>().Where(x => x.Field<int>("ParentID") == 0);
  var notEqual0 = dt.Rows.Cast<DataRow>().Where(x => x.Field<int>("ParentID") != 0);

You get a list of data rows with parent ids which are equal to 0 and a list which doesn't equal 0. 您将获得父ID等于0的数据行列表和不等于0的列表。

EDIT: 编辑:

I see you are attempting Select - Where is an alternative and does what you want to do. 我看到您正在尝试选择-在哪里可以选择,并且可以做您想做的事情。 This filters based on a bool condition so you can do where the ParentID is more than x or less than etc. 这会根据布尔条件进行过滤,因此您可以在ParentID大于x或小于etc的地方进行操作。

I hope you find this useful. 希望这个对你有帮助。

try this :: 尝试这个 ::

DataRow[] dt = dt.Select("Parent != '0'");
dt[0][Your Column Name] = your value;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM