c# - DataTable Select Query with daterange -
i have datatable in there 4 columns username,value,startdate,enddate has values below format.when select between these date range it's count 0 datatable has values. pls me .
username | value |startdate |enddate joe | 4 |28-08-2015 12:12:26 am|30-08-2015 12:29:26 pm| datarow[] drdocdetails = dtdlcd.select("username =\'" + susername + "\' , value =\'" + value + "\' , startdate >= #" + convert.todatetime(sprocessstart).tostring("yyyy-mm-dd hh:mm:ss tt") + "# , enddate < #" + convert.todatetime(sprocessend).tostring("yyyy-mm-dd hh:mm:ss tt") + "#");
your code working me, check code
string susername ="joe"; string value ="4"; string sprocessstart = "28-08-2015 12:12:26 am"; string sprocessend = "30-08-2015 12:29:26 pm"; datatable dtdlcd = new datatable(); datacolumn dtcolumn = new datacolumn("username"); dtcolumn.defaultvalue = "joe"; dtdlcd.columns.add(dtcolumn); datacolumn dtcolumn1 = new datacolumn("value"); dtcolumn1.defaultvalue = "4"; dtdlcd.columns.add(dtcolumn1); datacolumn dtcolumn3 = new datacolumn("startdate",typeof(datetime)); dtcolumn3.defaultvalue = "28-08-2015 12:12:26 am"; dtdlcd.columns.add(dtcolumn3); datacolumn dtcolumn4 = new datacolumn("enddate", typeof(datetime)); dtcolumn4.defaultvalue = "30-08-2015 12:29:26 pm"; dtdlcd.columns.add(dtcolumn4); datarow drow = dtdlcd.newrow(); dtdlcd.rows.add(drow); datarow[] drdocdetails = dtdlcd.select("username = '" + susername + "' , value = '" + value + "' , startdate = '" + convert.todatetime(sprocessstart).tostring("yyyy-mm-dd hh:mm:ss tt") + "' , enddate = '" + convert.todatetime(sprocessend).tostring("yyyy-mm-dd hh:mm:ss tt") + "'"); int count = drdocdetails.count();
Comments
Post a Comment