Problem in filtering records using Dataview (C#3.0)
Posted
by Newbie
on Stack Overflow
See other posts from Stack Overflow
or by Newbie
Published on 2010-05-07T02:21:10Z
Indexed on
2010/05/07
2:28 UTC
Read the original article
Hit count: 273
c#3.0
I have a data table . The data table is basically getting populated from excel sheet. And there are many excel sheets. Henceforth, I have written a utility method for accomplishing the same. Now in some of the excel sheets, there are date columns and in some it is not(only text/string).
My function is populating the values properly into the datatable from the excell sheet. But there are many blank rows in the excel sheets some are filled with NULL , some with " ".
So I need to filter those records (which are NULL or " " ) first before further processing.
What I am after is to use a dataview and apply the filter over there.
DataView dv = dataTable.DefaultView;
dv.RowFilter = ColumnName + " <> ''";
Well by using metedata (GetOleDbSchemaTable(OleDbSchemaGuid.Columns, restrection)) I was able to get the column names from the excel sheet , so getting the column names is not an issue.
But the problem is as I said in some Excel sheet there are date fileds some are not.
So the Filter condition of the Dataview needs to be proper. If I apply the above logic, and if it encounters a Datafield, it is throwing error
Cannot perform '<>' operation on System.DateTime and System.String.
Could you people please help me out?
I need to filter columns(not known at compile time + their data types) which can have NULL and " "
I am using C#3.0
Thanks
© Stack Overflow or respective owner