I have a column ‘date’ in my DataSet. I would like to filter this column by the current date.
I want to display all the orders just for today (current date).
I tried this but it’s not working:
DataSet ds = new DataSet();
ds.ReadXml("C:\\sites.xml");
dataGridView1.DataSource = ds.Tables[0];
this.dataGridView1.Columns[1].Visible = false;
//filter
ds.Tables[0].DefaultView.RowFilter = "date = '" + DateTime.Now.ToString() + "'";
XML file :
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<sites xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<site technical="1">
<name>brian</name>
<url>www.microsoft.com</url>
<date>01/02/2012</date>
</site>
<site technical="2">
<name>Mike</name>
<url>www.news.com</url>
<date>01/02/2012</date>
</site>
<site technical="3">
<name>leslie</name>
<url>www.cnet.com</url>
<date>02/01/2012</date>
</site>
<site technical="4">
<name>rebeca</name>
<url>www.gamespot.com</url>
<date>01/01/2012</date>
</site>
<site technical="5">
<name>jenifer</name>
<url>www.google.com</url>
<date>02/01/2012</date>
</site>
</sites>
You have to use number sign
#instead of apostrophe'.Try this:
source: http://www.csharp-examples.net/dataview-rowfilter/
UPDATE:
base on the date from your XML record, format date with “MM/dd/yyyy“