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
Post a Comment