I'm trying to search in DataTable with three string columns[start_date, end_date, expected_visits] using LINQ, but the third column has many lines as shown
So I split the third one with \n but I want to loop over date to compare it with text of txtSearchYear and return the result as DataTable, When I tried to use ForEach as shown in my code, An error appeared with me says A local or parameter named 'e' cannot be declared in this scope because that name is used in an enclosing local scope to define a local here is my code ...
var tblResult = tbl .AsEnumerable() .Where(x => x.Field<string>("start_date").Substring(0, 4).Equals(txtSearchYear.Text.Trim()) || x.Field<string>("end_date").Substring(0, 4).Equals(txtSearchYear.Text.Trim()) || x.Field<string>("expected_visits").Split('\n').ToList().ForEach((e) => { e.Substring(0, 4).Equals(txtSearchYear.Text.Trim()) })); if (tblResult.Any()) { GetData(tblResult.CopyToDataTable()); } else { DGVData.Rows.Clear(); } https://stackoverflow.com/questions/66083243/split-field-a-string-and-compare-each-value-with-string-linq-c-sharp February 07, 2021 at 08:00AM

没有评论:
发表评论