使用条件从数据集中获取记录

本文关键字:集中 获取 记录 数据集 数据 条件 | 更新日期: 2023-09-27 18:19:55

我想从数据集中获取从日期到日期之间的一些记录。但是同一列中的fromdate和todate。。

 **Expression :** 
  string expression = "punchDate >='" + txtfromdate.Text + "' and PunchDate <='" + txttodate.Text + "' ";
            findbyexpression(expression);

此表达式返回同一月份的记录。假设我想获取2011年2月12日至2011年1月10日的记录,意味着它不会返回记录。。。

 protected void findbyexpression(string Expression)
{
    try
    {
        DataTable dt1 = new DataTable();
        DataSet4TableAdapters.sp_getalltimesheetTableAdapter TA = new DataSet4TableAdapters.sp_getalltimesheetTableAdapter();
        DataSet4.sp_getalltimesheetDataTable DS = TA.GetData();
        DataTable DT = new DataTable();
        DT = DS[0].Table;
        DataRow[] foundRows;
        foundRows = DT.Select(Expression);
        dt1 = foundRows.CopyToDataTable();
        Session["TaskTable"] = dt1;
        grdvw.DataSource = Session["TaskTable"];
        grdvw.DataBind();
    }
    catch (Exception e2)
    {
        ScriptManager.RegisterStartupScript(this, this.GetType(), "temp", "<script language='javascript'>alert('" + e2.Message + "');</script>", false);
    }
}

使用条件从数据集中获取记录

    string expression = string.Format("punchDate>=convert(datetime,'{0}',105) and PunchDate <=convert(datetime,'{1}',105) ", txtfromdate.Text,txttodate.Text);

//这可能是工作