Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using datagridview rowfilter with dates
Message
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
Using datagridview rowfilter with dates
Environment versions
Environment:
C# 2.0
OS:
Windows Server 2003
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01381358
Message ID:
01381358
Views:
69
I am trying to filter a datagridview with a date range. I found a site that had the syntax but I cannot get the filter to work. I don't get an error but I don't get the records I should, either. Here's my code:
        private void btnLocOfficeNotes_Click(object sender, EventArgs e)
        {
            string filterON = "";            
            DateTime begDate, endDate;
            bool testDateOK = DateTime.TryParse(this.mtxtBegDate.Text, out begDate);
            if (testDateOK)
            {
                if (!mmType.IsEmpty(filterON))
                    filterON += " AND ";
                filterON += "EnterDateTime >= '" + begDate.ToShortDateString() + "'";
               //Add hours and minutes to make sure that I get all entries for the end date, regardless of time
                if (this.mtxtEndDate.Text.Substring(0, 3) == "  /")
                {
                    endDate = begDate.AddHours(23).AddMinutes(59);
                }
                else
                {
                    testDateOK = DateTime.TryParse(this.mtxtEndDate.Text, out endDate);
                    if (testDateOK)
                        endDate = endDate.AddHours(23).AddMinutes(59);
                }
                filterON += " AND EnterDateTime <= '" + endDate.ToShortDateString() + "'";
            }

            DataTable dtON = (DataTable)oOfficeNote.GetCurrentDataSet().Tables[0];
            dtON.DefaultView.RowFilter = (filterON);
            dtON.DefaultView.RowStateFilter = DataViewRowState.ModifiedCurrent;
I used the dates 9/30/2008 - 10/01/2008 and there were definitely records meeting the criteria but I get an empty grid when I try it. I also tried this using # rather than single quotes as delimiters for the dates, but that didn't work either. Any ideas? Thanks.
Linda Harmes
HiBit Technologies, Inc.
Next
Reply
Map
View

Click here to load this message in the networking platform