Using RowFilter to filter dataview within DateTime values in a Dataset

Posted on 2009-02-16
Medium Priority
Last Modified: 2013-11-07
Hello Experts,

Using VS 2008
Windows Forms (not ASP.NET)

I am trying to filter a dataview based on Datetime values within a Dataset. For some reason I am not coming up with any matches when I should be. I am using the values of 2 DateTimePickers for my date ranges. I have even tried removing the DateTimePickers and hard coding in values that I know exist within the dataset still with no luck. See code below. Any ideas on what I am doing wrong? It appears as though I am just using the method incorrectly?

Thanks in advance.

//Define my variables to be used in the search. these are my 2 DateTimePickers. I have tried leaving off the "ToString()" method and leaving the variables as DateTime, also with no luck
string begin = dateTimeLater.Value.ToString("M/dd/yyyy 00:00");
string end = dateTimeEarlier.Value.ToString("M/dd/yyyy 23:59"); 
// At this point I have used a Messagebox to display the values of begin and end. They are correct.
//Create my dataview - this also works fine.
DataView gridView = new DataView(reserveTrackerDataSet.Tables["Authorizations"]);
//Try and filter gridview - THIS RETURNS NO MATCHES. I have verified that there is data in the dataset that DOES match the filter criteria, yet nothing is returned.  FYI - Date is of type DateTime in the dataset.
gridView.RowFilter = "Date IN (#" + begin + "#, #" + end + "#)";
//I have also hardcoded the date values directly in my RowFilter statement to determine if my variables were the problem like below, but still NO MATCHES even thou data in the dataset should match.
gridView.RowFilter = "Date IN (#1/01/2009 00:00#, #2/16/2009 23:59#)";

Open in new window

Question by:kalittaair
  • 2
LVL 22

Expert Comment

ID: 23654092

Is it a Access db you're connecting to? If it's SQL server you should write
gridView.RowFilter = "Date IN ('1/01/2009 00:00', '2/16/2009 23:59')";
Also this construct only match those particular dates. begin and end sounds like an interval, in that case you could use "Date BETWEEN '1/01/2009 00:00' AND '2/16/2009 23:59'".


Author Comment

ID: 23654549

Thanks for your reply. Yes, it is a SQL 2005 DB I am accessing. However, when using:
gridView.RowFilter = "Date BETWEEN ('1/01/2009 00:00' AND '2/16/2009 23:59')";
I get:
"The expression contains unsupported operator 'Between'."

I tried removing the parathesis like in your example. Still no luck.


Accepted Solution

kalittaair earned 0 total points
ID: 23656274
Thanks for trying but I figured it out.

gridView.RowFilter = "Date >= #" + begin + "# AND Date <= #" + end + "#";


Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question