mysql - saving parentheses or quotations into sql in vb.net -


i have save command on vb project. problem won't save texts " ' " or parentheses. think has sql command.. here code saving update

saving

  dim myadapter new mysqldataadapter             dim mydatatable new datatable             dim command new mysqlcommand             dim add string              add = "insert tracker.recordtracker (action_taken,marginal_note,remarks,type_of_document,referred_date,items,received_from,received_date,referred_to,recdate,refdate)values('" + acttaken.text + "','" + margnote.text + "','" + remarks.text + "','" + doctype.text + "','" + rfrldatelbl.text + "','" + itemtbx.text + "','" + rfromtbx.text + "','" + rcvdate.text + "','" + reftotbx.text + "' ,'" + rdate.text + "',@refdate)"             command = new mysqlcommand(add, connection)             refdate.customformat = "yyyy-mm-dd"               myadapter.selectcommand = command             myadapter.fill(mydatatable)             msgbox("data has been added.")             clearfield()             loaddatabase()              connection.close()             connection.dispose()         catch ex exception             msgbox(ex.message)         end try 

for update

try                 connection.open()                 rcvdate.text = rdate.text                 if refdate.checked = false                     rfrldatelbl.text = "____-__-__"                 else                     refdate.customformat = "yyyy-mm-dd"                     rfrldatelbl.text = refdate.text + " " + timeofday                 end if                  dim query string                 query = "update tracker.recordtracker set action_taken='" & acttaken.text & "', marginal_note='" & margnote.text & "', remarks='" & remarks.text & "',type_of_document='" & doctype.text & "', items = '" & itemtbx.text & "', referred_to='" & reftotbx.text & "', referred_date='" & rfrldatelbl.text & "',recdate='" & rdate.text & "',refdate='" & refdate.text & "' id = '" & id.text & "'"                  utos = new mysqlcommand(query, connection)                 reader = utos.executereader                  msgbox("data has been changed.")                 connection.close()                 loaddatabase()                  connection.close()                 connection.dispose()             catch ex exception                 msgbox(ex.message)             end try 

you've appended string forms sql query. want read on sql injection see why terrible idea. allow has access submitting values append string, control on database. want like:

dim sql string = "insert foo (baz) values (@baz)"  using cn new sqlconnection("your connection string here"), _     cmd new sqlcommand(sql, cn)      cmd.parameters.add("@baz", sqldbtype.varchar, 50).value = baz     cmd.executenonquery() 

to around issue.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -