Hi Nancy
The data is read from an XML file (which is produces by VFP8 SP1 CursorToXML() function) using the DataSet.ReadXml class. When viewed in datagrid the date is displayed as 2004-5-24.
I thought the data was a date type because if the column is sorted it is display in the correct date order.
I have managed to get the filter working using the following
DateTime d = DateTime.Today.AddMonths(-18);
AnimalsVw.RowFilter = "Dob <= '" + d.ToString("yyyy/MM/dd") + "'";
If I included { or ^ from your example an error was returned when the code was run.
I am a little puzzled why the value has to be converted to a string, if the Dob in the dataview is a date, or is the Dob column in the dataview stored as a string?
Thanks for everyone help.
John
>>I am trying to set a filter on a dataview to show all animals over 18 months. Here is the code I have tried.
>>
>>
>>this.AnimalsVw.RowFilter = "Dob < #" + DateTime.Today.AddMonths(-18) + "#" ;
>>
>>
>>and I have also tried
>>
>>
>>this.AnimalsVw.RowFilter = "Dob < '" + DateTime.Today.AddMonths(-18) + "'" ;
>>
>>
>>Neither on the filters works either causing an error or just not filtering any animals.
>
>Is 'Dob' a date type field? DateTime?
>
>Here's a tip for debugging problems like this. Build your expression up in parts. First create the date you want to target. Then, create the string. Check it. You'll find that the string is probably something like
>
>I'm sure you can see why that is an error. I think you want something like in the following example:
using System;
>
>namespace ConsoleApplication3
>{
> /// <summary>
> /// Summary description for Class1.
> /// </summary>
> class Class1
> {
> /// <summary>
> /// The main entry point for the application.
> /// </summary>
> [STAThread]
> static void Main(string[] args)
> {
> DateTime d = DateTime.Today.AddMonths(-18);
> string s = "Dob <= {^" + d.ToString("yyyy/MM/dd") + "}";
> Console.WriteLine("DateTime d = '{0}'",d);
> Console.WriteLine("string s = '{0}'",s);
> Console.ReadLine();
> }
> }
>}
>