Solved

Frustrating INSERT Error...

Posted on 2004-09-17
8
221 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi component that can load a DLL in design time? 8 74
Correct Component for Shopping Cart. 2 112
Base1 Encode/Decode 3 81
Tvertscrollbox like a whatsapp layout 5 34
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

856 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