a little background on skills. in 2006 taught self use vb6 communicate access database. had success , wrote couple of handy databases myself through tutorials , message boards. make lot has changed. needless i'm novice has become beginner.
on form load, see data in datagridview. when click row header on datagridview loads data text boxes. works how i'd to.
my problem adding new record. have searched site, found few suggestion thought might work, implemented them , can't them work. commit button want happen. if out there can fantastic. code follows:
public class form1 dim integer dim con new oledb.oledbconnection 'the connection object dim dbprovider string 'holds provider dim dbsource string 'holds data source dim myfolder string 'holds database folder dim thedatabase string 'holds database name dim fulldatabasepath string 'holds database path dim ds new dataset 'holds dataset object dim da oledb.oledbdataadapter 'holds dataadapter object dim sql string 'holds sql string public sub form1_load(sender object, e eventargs) handles mybase.load me.pv_tabletableadapter.fill(me.pvdbdataset1.pv_table) 'set provider dbprovider = "provider=microsoft.ace.oledb.12.0;" 'set database , database thedatabase = "/pvdb.accdb" myfolder = "c:\pipe vault" fulldatabasepath = myfolder & thedatabase 'set data source dbsource = "data source = " & fulldatabasepath 'set connection string con.connectionstring = dbprovider & dbsource 'open database con.open() 'store sql string , connection object data_adapter sql = "select * pv_table" da = new oledb.oledbdataadapter(sql, con) da.fill(ds, "pv_table") 'close database ' con.close() 'messagebox.show("database closed") end sub private sub datagridview1_rowheadermouseclick(sender object, e datagridviewcellmouseeventargs) handles datagridview1.rowheadermouseclick 'loads textboxs data datagrid object = datagridview1.currentrow.index txtlocation.text = datagridview1.item(0, i).value txtprojectname.text = datagridview1.item(1, i).value txtpipedate.text = datagridview1.item(2, i).value txtpipenumber.text = datagridview1.item(3, i).value txtpipesize.text = datagridview1.item(4, i).value txtaproxfootage.text = datagridview1.item(5, i).value txtinstalldate.text = datagridview1.item(6, i).value end sub private sub txtpipedate_click(sender object, e eventargs) handles txtpipedate.click monthcalendar1.visible = true end sub private sub monthcalendar1_dateselected(sender object, e daterangeeventargs) handles monthcalendar1.dateselected txtpipedate.text = monthcalendar1.selectionstart monthcalendar1.visible = false end sub private sub btnupdate_click(sender object, e eventargs) handles btnupdate.click dim cb new oledb.oledbcommandbuilder(da) ds.tables("pv_table").rows(i).item(1) = txtlocation.text ds.tables("pv_table").rows(i).item(2) = txtprojectname.text ds.tables("pv_table").rows(i).item(3) = txtpipedate.text ds.tables("pv_table").rows(i).item(4) = txtpipenumber.text ds.tables("pv_table").rows(i).item(5) = txtpipesize.text ds.tables("pv_table").rows(i).item(6) = txtaproxfootage.text ds.tables("pv_table").rows(i).item(7) = txtinstalldate.text da.update(ds, "pv_table") 'messagebox.show("data updated") end sub private sub btnaddnew_click(sender object, e eventargs) handles btnaddnew.click dim control 'enables text boxes each in me.controls if typeof textbox a.enabled = true end if next 'clears contents of text boxes txtlocation.clear() txtprojectname.clear() txtpipedate.clear() txtpipenumber.clear() txtpipesize.clear() txtaproxfootage.clear() txtinstalldate.clear() 'sets states of buttons btncommit.enabled = true btnaddnew.enabled = false btnupdate.enabled = false btndelete.enabled = false end sub private sub clear_click(sender object, e eventargs) handles clear.click btncommit.enabled = false btnaddnew.enabled = true btnupdate.enabled = true btndelete.enabled = true end sub private sub btncommit_click(sender object, e eventargs) handles btncommit.click dim newrow datarow = ds.tables("pv_table").newrow() dim cb new oledb.oledbcommandbuilder(da) newrow("location") = txtlocation.text newrow("project name") = txtprojectname.text newrow("pipe date") = txtpipedate newrow("pipe number") = txtpipenumber newrow("pipe size") = txtpipesize.text newrow("aprox footage") = txtaproxfootage.text newrow("install date") = txtinstalldate.text ds.tables("pv_table").rows.add(newrow) da.update(ds, "pv_table") end sub
Comments
Post a Comment