Calculate sum based on different dates -
i'm new stackoverflow , need problem. have table (sql 2014 , use vb.net) this:
id codfisc dal al 1 xxxxxxx 2017/08/08 2017/08/14
i have developed code:
dim date = date.parse(textbox2.text) dim b date = date.parse(textbox3.text) dim source2 string = webconfigurationmanager.connectionstrings("connectionstring").connectionstring dim sql2 string = "select sum(datediff(day, dal, al)+1) total tab1 codfisc = @codfisc , dal >=@dal , al <=@al" dim conn2 new sqlconnection(source2) conn2.open() dim cmd2 new sqlcommand(sql2, conn2) cmd2.parameters.addwithvalue("@codfisc", me.gridview1.selectedrow.cells(8).text) cmd2.parameters.addwithvalue("@dal", a) cmd2.parameters.addwithvalue("@al", b) dim dr2 sqldatareader dr2 = cmd2.executereader() while dr2.read() textbox4.text = dr2("total").tostring() if isdbnull(dr2("total")) textbox4.text = "0" end if end while conn2.close()
so if search 2017/08/08
2017/08/14
, textbox4.text=7
, correct! if search 2017/08/08
2017/08/13
textbox4.text=0
instead of textbox4.text=6
!!
thank everyone.
Comments
Post a Comment