0

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 ...

Daniel Hilgarth
  • 171,043
  • 40
  • 335
  • 443
Fernando
  • 111
  • 2
  • 3
  • 10
  • Ref this Post : [enter link description here][1] [1]: http://stackoverflow.com/questions/12928660/convert-different-format-of-datetime-to-specific-string-format#comment17551801_12928660 – Bala Kumar Oct 18 '12 at 14:45

2 Answers2

3

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)

Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
0

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.

shahkalpesh
  • 33,172
  • 3
  • 63
  • 88