vb.net - Loop, aggregate and return unique DataRow sum -
i have datagrid contains multiple transactions of customer's buy ins. want add transaction buy ins each customer , add result on related images. have @ moment gives me logic errors i.e. adding same amounts on more 1 images.
here structure of datagrid (column titles): [name,surname, buyin, type, starttime, transactionid, customerid] , here code:
dim tbactiveplayers datatable = me.activeplayerstableadapter.getdata() dim tbtemp new datatable ' table = dataset.tables("orders") ' declare object variable. dim objtotalbuyin object dim icount, ilbl integer ilbl = 1 dim viewuniqueplayers new dataview(tbactiveplayers) dim iactiveplayers integer = viewuniqueplayers.totable(true, "customerid").rows.count dim dtdatatable datatable = viewuniqueplayers.totable(true, "customerid") dim mylabel label icount = 0 dtdatatable.rows.count objtotalbuyin = tbactiveplayers.compute("sum(buyin)", "customerid = " & tbactiveplayers.rows(icount).item("customerid")) 'msgbox("name: " & tbactiveplayers.rows(icount + 1).item("name") & ", sumbuyin:" & sumobject.tostring & " resultcount:" & resultcount) ' mylabel = ctype(me.controls.find("lblplayer" & ilbl, true)(0), label) if not mylabel nothing mylabel.text = "empty seat" end if ' mylabel.text = tbactiveplayers.rows(icount).item("name") & environment.newline & _ "€" & objtotalbuyin.tostring mylabel.image = global.pokerbusiness.my.resources.resources.seatocc ilbl += 1 next
your filter function compute seems based off each row in tbactiveplayers, yet you're looping on each row (and counting rows of) view of unique players. brain compiler tells me might source of logic errors, because you're potentially computing sum filter that's using single, unique customer id more once. consider changing
objtotalbuyin = tbactiveplayers.compute("sum(buyin)", "customerid = " & tbactiveplayers.rows(icount).item("customerid")) to
objtotalbuyin = tbactiveplayers.compute("sum(buyin)", "customerid = " & dtdatatable.rows(icount).item("customerid"))
Comments
Post a Comment