delphi - MSAccess SQL Too few parameters. Expected 4 -


i'm using delphi xe2 , anydac , msaccess db.

the table 'timea' has 5 fields:

rec_no autonumber
app text
user_id text
pw text
comment memo

this code throws error below. query works fine in access query designer.

sql := 'insert [timea] (app, user_id, pw, comment) values ("zoo", "bill", "mi7", "liger");'; adconnection1.execsql(sql); 

project pwb.exe raised exception class emsaccessnativeexception message '[anydac][phys][odbc][microsoft][odbc microsoft access driver] few parameters. expected 4.'.

both sql , delphi using single quotes string boundaries. since want have singe quote inside string, have "escape" using doube single quote.

for example, if write s := 'guns''n''roses' varieble s contain string guns'n'roses - 12 characters, not 14.

be careful when concatenating string values, since might contain single quotes, too. recommended way write query in case is, example:

sql := 'insert table (col) values (' + quotedstr(val) + ')'; 

function quotedstr wll take care , double single quotes in string. essential avoid insertion hacks.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -