2012-01-11 65 views
0

我想從數據集中獲取fromdate到todate之間的某個記錄。但是在同一列中fromdate和todate。使用條件從數據集中獲取記錄

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

此表達式在同一個月內返回記錄。假設我想從'12 -02-2011' 記錄,以2011' 年10月1日是指它不返回記錄......

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); 
    } 
} 
+0

您的問題文本:從'12 - 02-2011'到10-01-2011'表示它不返回記錄...表示從開始日期到日期,但通常從日期開始小於或等於迄今..我希望你正確地說出你的問題文本.. – VS1 2012-01-19 08:42:34

+0

假設從日期:01-01-2012和todate 10-01-2011表示它返回正確的記錄。那麼從...開始日期:01-11-2011 Todate:10-01-2011表示它沒有得到任何記錄。其實這個日期包含一些記錄..請幫助我.. – 2012-01-19 08:44:49

回答

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

//這可能是工作!

相關問題