i starting in vb.net , trying update row in access database selected datagridview checkbox in vb.net.
here part of system:
here code:
private sub editio_linkclicked(byval sender system.object, byval e system.windows.forms.linklabellinkclickedeventargs) handles editio.linkclicked if myconnection.state = connectionstate.open myconnection.close() end if myconnection.connectionstring = connstring myconnection.open() if editio.text = "enable time in/out edit" try dim checkedrows = ( rows in admintabdisplay.rows.cast(of datagridviewrow)() cbool(rows.cells("ck").value) = true ).tolist if checkedrows.count > 0 dim sb new system.text.stringbuilder each row datagridviewrow in checkedrows sb.appendline(row.cells("last name").value.tostring) next dim cmd oledbcommand = new oledbcommand("update [roster1] set [edittime] = 'e' [last name] = '" & sb.tostring & "'", myconnection) dim dr oledbdatareader = cmd.executereader end if catch ex exception messagebox.show(ex.message) end try end if viewadmin() editio.text = "disable time in/out edit" end sub
it can check checkboxes selected , can update whole database when link clicked.
but every time add "where" clause after db command (which "where [last name] = '" & sb.tostring & "'"), doesn't update selected row.
also, use "employee id" column in replacement of "last name" column used in clause
if possible, please explain simple can be. i'm still beginner in vb.net. thank much! every appreciated!
never mind post. solved tiny detail.
i used "employee id" column instead of "last name" column shown in code above
it converted string (because of stringbuilder). converted integer code:
dim sb new system.text.stringbuilder each row datagridviewrow in checkedrows sb.appendline(row.cells("last name").value.tostring) next dim st string = sb.tostring dim value integer = cint(st)
and changed database command to:
dim cmd oledbcommand = new oledbcommand("update [roster1] set [edittime] = 'e' [employee id] = " & value & "", myconnection) dim dr oledbdatareader = cmd.executereader
Comments
Post a Comment