小编daf*_*Bit的帖子

DataTable过滤器,包含日期范围

我有一个我正在处理的程序的一部分需要过滤掉所有不必要的行,并且只根据从我的表单上的日期时间选择器控件中选择的开始和结束日期保留必要的行..csv文件包含以下所有日期作为示例:

  • 3/10/2015
  • 2015年3月9日
  • 2015年3月6日
  • 2015年3月5日
  • 2015年3月4日
  • 2015年3月3日
  • 2015年3月2日
  • 2015年2月27日
  • 2015年2月26日
  • 2015年2月25日
  • 2015年2月24日
  • 2015年2月23日
  • 2015年2月20日

如果我的日期时间选择器已被选中作为2015年2月18日开始,结束日期为2015年3月2日,我希望只能将这些项目包含在我的数据表中.我有一个方法已经反转数据行,但我需要知道如何过滤掉小于或等于结束日期,大于或等于开始日期的值.我的计划是在一个单独的方法中完成过滤,在该方法中,我传递通过读取.csv文件创建的现有表.

我的代码到目前为止如下:

public DataTable PopulateTable()
{
    DataTable stockTable = new DataTable();
    try
    {
        FileStream stream = new FileStream(BuildFilePath(), FileMode.Open);
        stream.Close();
    }
    catch (Exception ex)
    {
        MessageBox.Show("Unable to open filepath");
    }

    StreamReader reader = new StreamReader(BuildFilePath());
    string header = "";
    string line = "";
    char[] delimeter = { ',' };
    string[] headerData;
    string[] rowData;
    //read the header and add the names to the columns of the data …
Run Code Online (Sandbox Code Playgroud)

c# datatable ado.net

3
推荐指数
1
解决办法
4801
查看次数

标签 统计

ado.net ×1

c# ×1

datatable ×1