Assuming I have a column called A and I want to check if A is null or blank, what is the proper way to check for this using the DataView's RowFilter:
DataTable dt = GetData();
DataView dv = new DataView(dt);
dv.RowFilter = "A IS NOT NULL OR A IS NOT ''";
The above doesn't seem to work though.
RowFilter Property (System. Data) Gets or sets the expression used to filter which rows are viewed in the DataView.
Using a DataView, you can expose the data in a table with different sort orders, and you can filter the data by row state or based on a filter expression. A DataView provides a dynamic view of data in the underlying DataTable: the content, ordering, and membership reflect changes as they occur.
Are you tied to .net < 3.5? If not you can use linq to check the state of a column.
Otherwise there is an Isnull(,)
function like in T-SQL:
dv.RowFilter = "Isnull(a,'') <> ''";
I am assuming you need to retrieve all the records where the value in column A is neither null nor ''
The correct expr is:
dv.RowFilter = "A IS NOT NULL AND A <> ''";
And to retrieve the filtered records loop on dv.ToTable() like this:
foreach (DataRow dr in dv.ToTable().Rows)
Console.WriteLine(dr["A"]);
This should work ... cheers!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With