vb.net - update the column specifed in the text box from the server -


i want update column of table column name entered in textbox while executing. following code not performing action. textbox14 contains column name , textbox12 consists value updated.

        dim squery string = "select name,days definedleave"                         dim cmd6 sqlcommand = new sqlcommand(squery, con)                         dim dr6 sqldatareader = cmd6.executereader()                         dim integer = 0                         while dr6.read()                             try                                 s = dr6(i).tostring                                 textbox14.text = s                                 = dr6(i + 1).tostring                                 textbox12.text =                                dim sql = "update empleave set " & textbox14.text.trim & "=@na epid='" + txtcode.text + "'"                                  using com7 = new sqlcommand(sql, con)                                     com7.parameters.addwithvalue("@na", textbox12.text)                                     com7.executenonquery()                                 end using                             catch ex exception         msgbox("hello")     end try                         end while                         com7.dispose()                         dr6.close() 

unfortunately, parameters can used values, not identifiers. they're variables in vb - can't use contents of 1 variable stand variable in vb either.

the silly thing you're trying use parameter can't , can, epid value, use string concatenation. code should this:

dim sql = "update empleave set [" & textbox14.text & "] = @na epid = @epid"  using com7 = new sqlcommand(sql, con)     com7.parameters.addwithvalue("@na", textbox12.text)     com7.parameters.addwithvalue("@epid", txtcode.text)      com7.executenonquery() end using 

that still leaves open sql injection though, should make absolutely sure validate column name first. in fact, should query database column names first , put them in combobox. way guaranteed user select valid value.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -