Solved

Frustrating INSERT Error...

Posted on 2004-09-17
8
223 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

695 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