sql server 2008 - How to change row color in datagridview by comparing two columns from different tables using vb.net? -
no success!
if user of tblcon
billmonth of tbltrns
exists in tbltrns
highlight rows of tblcon
red color
code:
private sub checkexist() each row datagridviewrow in datagridview1.rows conobj = new sqlconnection(constr) conobj.open() dim qry string = "select * tbltrns username=@username , bill_month=@bill_month" cmdobj = new sqlcommand(qry, conobj) cmdobj.parameters.addwithvalue("@bill_month", datetimepicker1.text) cmdobj.parameters.addwithvalue("@username", (row.cells("user").value.tostring)) drobj = cmdobj.executereader() if drobj.hasrows row.defaultcellstyle.backcolor = color.red end if next conobj.close() end sub
query grid
public function getdata() dataview conobj = new sqlconnection(constr) conobj.open() cmdobj = new sqlcommand dsobj = new dataset daobj = new sqldataadapter() dim selectqry = "select username[user],doj[connection date],packagename[package],profilename[profile],billing[payment],fees[fees],connectionstatus[status] tblcon" cmdobj.commandtext = selectqry cmdobj.connection = conobj daobj.selectcommand = cmdobj daobj.fill(dsobj) tvobj = dsobj.tables(0).defaultview return tvobj conobj.close() end function
query changed in getdata no success. please guide ...........................................................................................................................................................................................................................................
public function getdata() dataview conobj = new sqlconnection(constr) conobj.open() cmdobj = new sqlcommand dsobj = new dataset daobj = new sqldataadapter() dim selectqry = dim selectqry = "select username[user],doj[connection date],packagename[package],profilename[profile],billing[payment],fees[fees],connectionstatus[status], (select isnull(count(*), 0) tbltrns tbltrns.username = tblcon.username , bill_month = '" & datetimepicker1.text & "') [comparison] tblcon" cmdobj.commandtext = selectqry cmdobj.connection = conobj daobj.selectcommand = cmdobj daobj.fill(dsobj) tvobj = dsobj.tables(0).defaultview return tvobj conobj.close() end function
i recommend fill new column in grid value comparison , set it's visibility false. can subselect or left join on second table (if wish example post query fills grid).
based on comparison column can use cellpainting event of gridview. this:
private sub grdgridview_cellpainting(byval sender object, byval e system.windows.forms.datagridviewcellpaintingeventargs) handles grdgridview.cellpainting if e.rowindex >= 0 if grdgridview.rows(e.rowindex).cells("colcomparison").value <> "0" , not isnothing(grdgridview.rows(e.rowindex).cells("colcomparison").value) e.cellstyle.backcolor = color.orangered e.cellstyle.selectionbackcolor = color.indianred end if end if end sub
Comments
Post a Comment