Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
RowFilter and Dates
Message
From
24/05/2004 12:00:57
 
General information
Forum:
ASP.NET
Category:
ADO.NET
Miscellaneous
Thread ID:
00906425
Message ID:
00906560
Views:
14
>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
'Dob < 11/24/2002 12:00:00 AM'
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();
		}
	}
}
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform