DataView RowFilter determine if a DateTime column is greater than another DateTime column plus 6 months

StackOverflow https://stackoverflow.com/questions/15817512

سؤال

I have a dataview which has two columns. A and B each column has a date in it of type DateTime.

I would like to filter the dataview to only show rows where dates in A are greater than dates in B plus 6 months

A > (B+6months)

Here is what I have tried with no success.

DataView.RowFilter = "A > System.DateTime(B).AddMonths(6)";

DataView.RowFilter = "A > B.AddMonths(6)";

I appreciated any help given.

هل كانت مفيدة؟

المحلول

I am not a C# expert, but I believe you can use Linq to create the DataView as follows:

DataTable dt = new DataTable("MyTable"); // example data container

...

DataView dv = (from d in dt.AsEnumerable() where ((DateTime)d["A"]) > ((DateTime)d["B"]).AddMonths(6) select d).AsDataView();
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top