sql - I Cannot Update my database -


whats wrong these?

my module is:

imports system.data.oledb module module1     public con oledbconnection = new oledbconnection("provider=microsoft.jet.oledb.4.0;data source=d:\citeval\system7\system7\evaluation.mdb")     public da oledbdataadapter     public dr oledbdatareader     public cmd oledbcommand     public ds = new dataset     public currentrow integer     public sql string end module 

btn update

try     dim str string     str = "update studentsrecord set idnumber="     str += """" & txtidnumber.text & """"     str += " idnumber="     str += txtidnumber.text.trim()     con.open()     cmd = new oledbcommand(str, con)     cmd.executenonquery()     con.close()     con.open()     str = "update studentsrecord set firstname="     str += """" & txtfirst.text & """"     str += " idnumber="     str += txtidnumber.text.trim()     con.open()     cmd = new oledbcommand(str, con)     cmd.executenonquery()     con.close()     con.open()     str = "update studentsrecord set lastname="     str += """" & txtlast.text & """"     str += " idnumber="     str += txtfirst.text.trim()     cmd = new oledbcommand(str, con)     cmd.executenonquery()     con.close()     con.open()     str = "update studentsrecord set course="     str += """" & cbocourse.text & """"     str += " idnumber="     str += txtidnumber.text.trim()     cmd = new oledbcommand(str, con)     cmd.executenonquery()     con.close()     con.open()     str = "update studentsrecord set password="     str += """" & txtpassword.text & """"     str += " idnumber="     str += txtidnumber.text.trim()     cmd = new oledbcommand(str, con)     cmd.executenonquery()     con.close()     ds.clear()     da = new oledbdataadapter("select * studentsrecord order id", con)     da.fill(ds, "evaluation")     msgbox("updated successfully...") catch ex exception     msgbox(ex.message & "," & ex.source)     if con.state = connectionstate.open con.close() end try 

you don't have issue separate update statement each field, can update multiple fields in single update statement. better choice use parametrized query instead of concatenating strings.

try inside of try/catch block:

dim str string str = "update studentsrecord set firstname = @firstname, lastname = @lastname,  course = @course, password = @password  idnumber = @idnumber " cmd = new oledbcommand(str, con) cmd.parameters.addwithvalue("@firstname", txtfirst.text) cmd.parameters.addwithvalue("@lastname", txtlast.text) cmd.parameters.addwithvalue("@course", cbocourse.text) cmd.parameters.addwithvalue("@password", txtpassword.text) cmd.parameters.addwithvalue("@idnumber", txtidnumber.text.trim())  con.open() cmd.executenonquery()  ds.clear() da = new oledbdataadapter("select * studentsrecord order id", con) da.fill(ds, "evaluation")  msgbox("updated successfully...") 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -