sql - C# Reporting via query -
hi have code here
sqlconnection con = new sqlconnection(properties.settings.default.storedbconnection); sqldataadapter da = new sqldataadapter(); private void form1_load(object sender, eventargs e) { string test = datetime.now.tostring("yyyy-mm-dd"); var dept = properties.settings.default.giftdepartment; messagebox.show(""+test+""); sqlcommand cmd = new sqlcommand("select deptno,deptsales,deptcustomers storesalesdetail deptno="+dept+" , procdate>="+test+"", con); sqldataadapter da = new sqldataadapter(cmd); dataset1 ds = new dataset1(); da.fill(ds); reportviewer1.localreport.datasources.clear(); reportviewer1.localreport.datasources.add(new microsoft.reporting.winforms.reportdatasource("dataset1", ds.tables[1])); this.reportviewer1.refreshreport(); }
sample data in table
2013-05-03 00:00:00.000,2,120.0000,1,1 2013-05-04 00:00:00.000,2,50.0000,1,1
test returns date 2013-05-04 why report return both date in >= query?
try using datediff more precision. wrap input value [test] in single quotes.
sqlcommand cmd = new sqlcommand("select deptno,deptsales,deptcustomers storesalesdetail deptno="+dept+" , datediff(d, '" + test + "', procdate) >=0", con);
Comments
Post a Comment