vb.net - Check before dataser make changes -
i use datagridview , populate using dataset follows:
private getgeschaftdataset new dataset public function getdataset() dataset implements idal.getdataset dim strcon = new appsettingsreader().getvalue("connectionstring", gettype(system.string)).tostring() using con new sqlconnection(strcon) using cmd new sqlcommand("select * t_marke", con) con.open() ' create data adapter in method , throw away afterwards using getprojectsdataadapter = new sqldataadapter(cmd) getprojectsdataadapter.fill(getgeschaftdataset, "trial1") end using end using end using return getgeschaftdataset end function
when user ends work save changes db this:
public sub makechangesdataset() implements idal.makechangesdataset if not getgeschaftdataset.haschanges messagebox.show("no changes save", "informacja", messageboxbuttons.ok, messageboxicon.warning) else dim integer try using myconnection = new sqlconnection(strcon) using cmd new sqlcommand("select * t_marke", myconnection) myconnection.open() ' create data adapter in method , throw away afterwards using getprojectsdataadapter = new sqldataadapter(cmd) dim cmdbuilder new sqlcommandbuilder(getprojectsdataadapter) = getprojectsdataadapter.update(getgeschaftdataset, "trial1") end using end using end using messagebox.show("updated" & & " marke", "informacja", messageboxbuttons.ok, messageboxicon.information) catch ex exception msgbox(ex.message) end try end if end sub
however check whether not duplicate data, in case if table contains columns: id , name - don't want update if user placed existing name. how achieve or should check on datagrid level?
there ways this.
open connection , select count rows name , if 0 in same connection execute insert.
using stored procedure above.
create unique index on name column
i use third.