How to delete multiple rows in datagridview and database using vb.net window forms -
i have data gridview loads these codes:
mycom.connection = cn mycom.commandtext = <sql> select username,activity,cdate `date` tbl_activity </sql>.value dim myadap new mysqldataadapter(mycom) dim mydt new datatable grdactivity.columns.add(colcb) myadap.fill(mydt) grdactivity.datasource = mydt myadap.dispose()
and have delete button these codes:
dim selected integer selected = grdactivity.selectedrows.count if grdactivity.selectedrows.count > 0 'you may want add confirmation message, , if user confirms delete integer = 0 selected myr.close() mycom.connection = cn mycom.commandtext = "delete tbl_activity id = '" & & "' " mycom.executereader() myr.close() next else messagebox.show("select 1 row before hit delete") end if
can me right codes can delete databases bounded rows not in datagridview directly database.. thanks..
don't dispose of dataadapter, can use update database. if configure myadap appropriate insert, update , delete commands button click code becomes nothing more error handling and:
myadapt.update(mydt)
don't read data out of grid, let grid manipulate data bound , dataadapter handle rest. have complete example (for ms sql server) here
Comments
Post a Comment