【发布时间】:2015-04-27 12:07:48
【问题描述】:
我的数据集中有一列“日期”。我想按当前日期过滤此列。 我想只显示今天(当前日期)的所有订单。
我试过了,但它不起作用:
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 文件:
<?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>
【问题讨论】:
-
“它不起作用”并没有提供人们认为的那么多信息。如果是错误,请提供消息。如果结果出乎意料,请告诉我们这是什么以及您的预期。
-
我没有收到错误消息,当我尝试过滤时,我的列在 datagridview 中是空的。可能是 XML 文件。