sql - Save when new record and update when edit on data occurs -


i have code save button , update button there way can combine 2 commands in 1 button?

for example when click 'save/update button' save on database if new record , rather update if system found there record on database , save edited data's

code save button

dim sqlconn new sqlclient.sqlconnection     sqlconn.connectionstring = "server = skpi-apps1;" & _     "database = eoems;integrated security=true"     try         dim mycommand new sqlcommand         sqlconn.open()         mycommand = new sqlcommand("insert tblofficeequipmentprofile(oe_category,oe_subcategory,oe_id,oe_name,oe_user,oe_brand,oe_model,oe_specs,oe_serialno,oe_propertyno,oe_macaddress,oe_static_ip,oe_vendor,oe_purchasedate,oe_warrantyinclusiveyear,oe_warrantystatus,oe_status,oe_dept_code,oe_location_code,oe_remarks) values('" & cmbcategory.text & "','" & cmbsubcategory.text & "','" & txtoeid.text & "','" & txtname.text & "','" & txtuser.text & "','" & cmbbrand.text & "','" & cmbmodel.text & "','" & txtspecs.text & "','" & txtserialno.text & "','" & txtpropertyno.text & "','" & txtmacaddress.text & "','" & txtstaticip.text & "','" & txtvendor.text & "','" & txtpurchasedate.text & "','" & txtwarrantyinclusiveyear.text & "', '" & txtwarrantystatus.text & "','" & txtstatus.text & "','" & cmbdeptcode.text & "','" & cmblocationcode.text & "','" & txtremarks.text & "')", sqlconn)         mycommand.executenonquery()         messagebox.show("office equipment profile added")         sqlconn.close()     catch ex exception         msgbox(ex.message)     end try 

code update button (note: still update button has error still trying fix)

dim sqlconn new sqlclient.sqlconnection     sqlconn.connectionstring = "server = skpi-apps1;" & _     "database = eoems;integrated security=true"      dim mycommand new sqlcommand       try          'update command         sqlconn.open()          mycommand = new sqlcommand("update tblofficeequipmentprofile set oe_category = '" & cmbcategory.text & "',oe_subcategory = '" & cmbsubcategory.text & "', oe_name = '" & txtname.text & "', oe_user = '" & txtuser.text & "', oe_brand = '" & cmbbrand.text & "', oe_model = '" & cmbmodel.text & "', oe_specs = '" & txtspecs.text & "', oe_serialno = '" & txtserialno.text & "', oe_propertyno = '" & txtpropertyno.text & "', oe_macaddress = '" & txtmacaddress.text & "', oe_static_ip = '" & txtstaticip.text & "', oe_vendor = '" & txtvendor.text & "', oe_purchasedate = '" & txtpurchasedate.text & "', oe_warrantyinclusiveyear = '" & txtwarrantyinclusiveyear.text & "', oe_warrantystatus = '" & txtwarrantystatus.text & "', oe_status = '" & txtstatus.text & "', oe_dept_code = '" & cmbdeptcode.text & "', oe_location_code = '" & cmblocationcode.text & "', oe_remarks ='" & txtremarks.text & "' oe_id ='" & txtoeid.text & "'", sqlconn)         dim icnt integer = mycommand.executenonquery()         messagebox.show("office equipment profile updated  " & icnt & "  records")     catch ex exception         msgbox(ex.message)     end try 

you create enum contains state:

 enum datastate       editing       adding       none  end enum 

then set class-level variable:

 private mdatastate datastate 

then set according whether adding or editing record, in save_click subroutine, use if-then.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -