How to INSERT a RECORD using SQL?? 
Author Message
 How to INSERT a RECORD using SQL??

Hi, I'm a new (and lost) database programmer.

I want to insert a record using SQL statements, but I can't make it work. I
can delete a record doing this:

CyGChildForm.LibroCyGQuery.SQL.Text := 'DELETE FROM "LibroCyG.DB" WHERE
Perceptor = "epa"';
CyGChildForm.LibroCyGQuery.ExecSQL;

But I haven't been able to insert any!!

If I try this:

CyGChildForm.LibroCyGQuery.SQL.Text := 'INSERT INTO "LibroCyG.DB"
(Perceptor, Importe) VALUES ("P1", 1000)';
CyGChildForm.LibroCyGQuery.ExecSQL;

then I get this error: "Field Value Required"

And if I try to do it like this:

CyGChildForm.Memo1CyGChildForm.LibroCyGQuery.SQL.Text := {'INSERT INTO
"LibroCyG" VALUES (INSERT INTO 'LibroCyG.DB' VALUES (123, 'NuF',
'11-10-2000', '21-12-2001', 'Per', 'Co', 10000, 10, 0, 8, 6, 56)

I get another error, don't remember exactly which one.

"LibroCyG.DB" is a Paradox 7 table, with fields defined as S, A, D, D, A, A,
N, N, N, N, N, N (S=Short, A=Alpha, D=Date, N=Number), and with no Key field
defined.

Any idea??
Well, I'm not sure wheter using SQL is the best way to insert or delete
records... Meybe there actually is another way. I'm using a TQuery.

I'd greatly appreciate any help!! Thank you.



Sat, 21 Jun 2003 03:36:48 GMT  
 How to INSERT a RECORD using SQL??
You are using the wrong kind of quotes for strings (' instead of "):

CyGChildForm.LibroCyGQuery.SQL.Text := 'INSERT INTO "LibroCyG.DB"
(Perceptor, Importe) VALUES (' + Quoted(P1) + ', 1000)';
CyGChildForm.LibroCyGQuery.ExecSQL;



Quote:
> Hi, I'm a new (and lost) database programmer.

> I want to insert a record using SQL statements, but I can't make it work.
I
> can delete a record doing this:

> CyGChildForm.LibroCyGQuery.SQL.Text := 'DELETE FROM "LibroCyG.DB" WHERE
> Perceptor = "epa"';
> CyGChildForm.LibroCyGQuery.ExecSQL;

> But I haven't been able to insert any!!

> If I try this:

> CyGChildForm.LibroCyGQuery.SQL.Text := 'INSERT INTO "LibroCyG.DB"
> (Perceptor, Importe) VALUES ("P1", 1000)';
> CyGChildForm.LibroCyGQuery.ExecSQL;

> then I get this error: "Field Value Required"

> And if I try to do it like this:

> CyGChildForm.Memo1CyGChildForm.LibroCyGQuery.SQL.Text := {'INSERT INTO
> "LibroCyG" VALUES (INSERT INTO 'LibroCyG.DB' VALUES (123, 'NuF',
> '11-10-2000', '21-12-2001', 'Per', 'Co', 10000, 10, 0, 8, 6, 56)

> I get another error, don't remember exactly which one.

> "LibroCyG.DB" is a Paradox 7 table, with fields defined as S, A, D, D, A,
A,
> N, N, N, N, N, N (S=Short, A=Alpha, D=Date, N=Number), and with no Key
field
> defined.

> Any idea??
> Well, I'm not sure wheter using SQL is the best way to insert or delete
> records... Meybe there actually is another way. I'm using a TQuery.

> I'd greatly appreciate any help!! Thank you.



Tue, 24 Jun 2003 20:38:33 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. trapping key violation error when inserting new record using SQL

2. Using SQL to insert record wth memo

3. Q: regarding using AppendRecord or Insert Record

4. Q : SQL and INSERT and Multi-Records

5. inserting lots of records in a sql anywhere database

6. How to insert records into indexed MS-SQL-Tables with Delphi C/S

7. Insert record in MS SQL through Delphi

8. Source: SQL on the fly for Updating, Inserting, and Deleting records

9. Insert record w/SQL Server identity field

10. SQL - problems with inserting record, giving constants and a SELECT statement

11. Insert records with SQL

12. using ttable/tdataset to insert rows into sql server

 

 
Powered by phpBB® Forum Software