Reputation: 111
i want to filter the data from a datatable using dataview row filter Datatable having the column name month having like this "01-04-2012 00:00:00". I want to get the get the data using this format..
This is my partial code
dv1 = dtable.DefaultView;
DateTime start = new DateTime(DateTime.Now.Year, 4, 1,0,0,0);
dv1.RowFilter =Convert.ToString(start); //"Month = '04-01-2011 00:00:00'";
it returns the following error : Syntax error: Missing operand after '00' operator. I can't able to fix this error please help me to do this ...
Upvotes: 0
Views: 848
Reputation: 33484
Looking at the code, you are missing the name of the column you would want to filter on.
For example:
dv1.RowFilter = string.Format("PurchaseDate = '{0}'", Convert.ToString(start));
The assumption is that PurchaseDate is the date inside the view, the data is to be filtered using.
Upvotes: 0
Reputation: 460370
You need to enclose the datetime value into #
. You also have to say what column you want to compare with this value.
For example:
dv1.RowFilter = String.Format(CultureInfo.InvariantCulture.DateTimeFormat,
"Date = #{0}#", start);
(where Date
is the actual name of your datetime-column)
Upvotes: 3