Updating VB.Net Database With SQL Update Statement -
so got update statement working , record in database being updated. program throwing error after record updated.
error
an unhandled exception of type 'system.data.oledb.oledbexception' occurred in system.data.dll
additional information: changes requested table not successful because create duplicate values in index, primary key, or relationship. change data in field or fields contain duplicate data, remove index, or redefine index permit duplicate entries , try again.
code
dim variable string dsconnectionm.open() variable = "update member set memberid = '" & form3.tbid.text & "', forename = '" & form3.tbfn.text & "' " dim cmd oledbcommand = new oledbcommand(variable, dsconnectionm) cmd.executenonquery() dsconnectionm.close()
i don't know if normal when ran second access file database created
this shows contents of "member" in databse
edited
i started using parameters advised error.
error
an unhandled exception of type 'system.data.oledb.oledbexception' occurred in system.data.dll
additional information: syntax error in update statement.
code
dim variable string dsconnectionm.open() variable = "update member set forename = @forename, surname = @surname, dob = @dob, section = @section, postcode = @postcode, hometel = @hometel, mobiletel = @mobiletel, addressline1 = @addressline1, addressline2 = @addressline2, city = @city, emailaddress = @emailaddress, p/gforename = @p/gforename, p/gsurname = @p/gsurname memberid = @memberid" dim cmd oledbcommand = new oledbcommand(variable, dsconnectionm) cmd.parameters.addwithvalue("@memberid", form3.tbid.text) cmd.parameters.addwithvalue("@forename", form3.tbfn.text) cmd.parameters.addwithvalue("@surname", form3.tbsn.text) cmd.parameters.addwithvalue("@dob", form3.dtpdob.value) cmd.parameters.addwithvalue("@section", form3.tbsr.text) cmd.parameters.addwithvalue("@postcode", form3.tbpc.text) cmd.parameters.addwithvalue("@hometel", form3.tbht.text) cmd.parameters.addwithvalue("@mobiletel", form3.tbmt.text) cmd.parameters.addwithvalue("@addressline1", form3.tbal1.text) cmd.parameters.addwithvalue("@addressline2", form3.tbal2.text) cmd.parameters.addwithvalue("@city", form3.tbc.text) cmd.parameters.addwithvalue("@emailaddress", form3.tbea.text) cmd.parameters.addwithvalue("@p/gforename", form3.tbpgfn.text) cmd.parameters.addwithvalue("@p/gsurname", form3.tbpgsn.text) cmd.executenonquery() dsconnectionm.close()
usually don't update
pk
of table. in form id
should read only. , if change other value, use id
find row update
variable = "update member " & "set forename = '" & form3.tbfn.text & "' " "where memberid = '" & form3.tbid.text & "'
and need use paramethers, other wise vulnerable sql injection
Comments
Post a Comment