vb.net - parsing database columns and values to MySQL statement in module -


i'm trying create dynamic mysql insert into...where not exist statement parsing table name, array of columns, array of values , conditional column , value subroutine in separate module keep hitting column count doesn't match value count @ row 1 error. below code:

sub insertrecord(byval tbl string, byval cols() string, byval params() string, _                       byval colcondition string, byval paramcondition string) 'as string      'create new string of columns     dim mycols string = ""     each col string in cols         mycols &= col & ", "     next      dim newcols string = mycols.remove(mycols.count - 2, 2)     msgbox(newcols)     dim scols string = newcols.insert(0, "`").replace(", ", "`, `") & "`"     msgbox(scols)        'create new string of parameters     dim myparams string = ""     each param in params         myparams &= param & ", "     next      dim newparams string = myparams.remove(myparams.count - 2, 2)     msgbox(newparams)     dim sparams string = newparams.insert(0, "'").replace(", ", "', '") & "'"     msgbox(sparams)     'end       dim p string = paramcondition.insert(0, "'") & "'"        'try     'dim insremarks string = "done"     con = new mysqlconnection("server=localhost; database=etms; uid=root; pwd=;")     coma = new mysqlcommand      'insert new record.     'this gives error     coma.commandtext = "insert " & tbl & " (" & scols & ") select * (select @params) tmp "     coma.commandtext &= "where not exists (select " & colcondition & " " & tbl & " " & colcondition & " = @param) limit 1"     coma.parameters.addwithvalue("@param", p)     coma.parameters.addwithvalue("@params", sparams)        'this static code works fine.     'coma.commandtext = "insert state (`st_state`, `ctry_id`) select * (select 'a', '1') tmp "     'coma.commandtext &= "where not exists (select st_state state st_state = 'a') limit 1"        coma.connection = con      con.open()     coma.executenonquery()     con.close()      'release used components     coma.parameters.clear()     coma.dispose()     coma = nothing     con = nothing      msgbox("done.")      'return insremarks      'catch ex exception     'msgbox(ex.message.tostring & vbcrlf & vbcrlf & coma.commandtext.tostring)     'return "error"     'end try  end sub 

as seen, tried lot of permutations (introducing inverted quotation marks) no avail.

i'll glad if out.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -