Solved

Frustrating INSERT Error...

Posted on 2004-09-17
8
217 Views
Last Modified: 2010-04-05
Hi,

Can any experts fin and error in the following insert statement.  I keep getting the following error but for the life of me can't find a problem.  It work find in Access...

---------------------------
Debugger Exception Notification
---------------------------
Project Application1.exe raised exception class EOleException with message 'Syntax error in INSERT INTO statement'. Process stopped. Use Step or Run to continue.
---------------------------
OK   Help  
---------------------------



  CreateUserQuery.SQL.Clear;
  QueryString := ''
    + 'INSERT INTO Users (FullName,Username,Password) VALUES ('
    + '''' + edtFullName.Text + ''''
    + ','
    + '''' + edtUsername.Text + ''''
    + ','
    + '''' + edtPassword.Text + ''''
    + ')'
    + '';
  try
    CreateUserQuery.SQL.Text := QueryString;
    CreateUserQuery.ExecSQL;
  except
    on e: exception do
      ShowMessage('Error :' + E.message);
  end;

Hope you can help.

Bego.

0
Comment
Question by:begonz
8 Comments
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 12083216
CreateUserQuery.SQL.Clear;
  QueryString := ''
    + 'INSERT INTO Users (FullName,Username,Password) VALUES ('
    + QuotedStr( edtFullName.Text)+','
    + QuotedStr(edtUsername.Text)+','
    + QuotedStr(edtPassword.Text )+')';
  try
    CreateUserQuery.SQL.Text := QueryString;
    CreateUserQuery.ExecSQL;
  except
    on e: exception do
      ShowMessage('Error :' + E.message);
  end;

F68 ;-)
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 12083232
sorry, posted too early

this one is corrected
...
QueryString := 'INSERT INTO Users (FullName,Username,Password) VALUES ('
    + QuotedStr( edtFullName.Text)+','
    + QuotedStr(edtUsername.Text)+','
    + QuotedStr(edtPassword.Text )+')';
...
0
 

Author Comment

by:begonz
ID: 12089443
Sorry, same problem....  As soon is it executes CreateUserQuery.ExecSQL; the error appears.  Anymore help?????

Thanks.
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 12089455
So there's something that come from the edit fields....are you sure about the values passed by them?
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 5

Expert Comment

by:tzxie2000
ID: 12089748
how about test AnsiQuotedStr ?
QueryString := 'INSERT INTO Users (FullName,Username,Password) VALUES ('
    + AnsiQuotedStrr( edtFullName.Text)+','
    + AnsiQuotedStr(edtUsername.Text)+','
    + AnsiQuotedStr(edtPassword.Text )+')';

if still error
you can set a point before
CreateUserQuery.SQL.Text := QueryString;
and add a watch about CreateUserQuery.SQL.Text
and paste the value in watch in the comment
this will let us more easy to determine the questioon
0
 
LVL 10

Accepted Solution

by:
Jacco earned 125 total points
ID: 12090685
In some database systems USERNAME, PASSWORD might be reserved words. If they are used as fields in tables some RDBMSs have special quote chars to allow using them.

Microsoft SQL Server for example allow for there use if you squarebrace them.

QueryString :=  'INSERT INTO Users (FullName,[Username],[Password]) VALUES ('

I am not sure how other RDBMSs so this.

Regards Jacco
0
 
LVL 45

Expert Comment

by:aikimark
ID: 12093748
try:
QueryString :=  'INSERT INTO [Users] ... '
0
 

Author Comment

by:begonz
ID: 12107594
Thanks Jacco, all working now, can't believe it was that simple!  
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now