inserting NULL values in queries

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
JensFudge
Posts: 35
Joined: Mon 12 Jan 2009 08:37

inserting NULL values in queries

Post by JensFudge » Fri 15 Oct 2010 11:30

Hi
How do I insert a NULL value in a query?

Q.SQL.Add('SELECT * FROM TABLE1');

Q.SQLINSERT.add('INSERT INTO TABLE1');
Q.SQLINSERT.add('(FIELD1, FIELD2)');
Q.SQLINSERT.add('VALUES');
Q.SQLINSERT.add('(:field1, field2)');

Q.open;

Q.insert;
Q.fieldByName('Field1').asInteger := NULL;
Q.fieldByName('Field2').asInteger := 4;
Q.Post;

That obviously wont work...
I have tried with .Clear, but got some exception..

Best regards
Jens Fudge

AndreyZ

Post by AndreyZ » Fri 15 Oct 2010 13:34

Hello,

You have an error in SQLInsert, the second parameter is written without colon.

AndreyZ

Post by AndreyZ » Fri 15 Oct 2010 13:34

You can use the following code:

Code: Select all

Q.FieldByName('Field1').Value := NULL;

JensFudge
Posts: 35
Joined: Mon 12 Jan 2009 08:37

Post by JensFudge » Fri 15 Oct 2010 13:40

AndreyZ wrote:Hello,

You have an error in SQLInsert, the second parameter is written without colon.
In case you hadn't noticed.. This is just example code off the top of my head..
I dont really have a table named Table1 with Field1 and Field2...
:wink:

JensFudge
Posts: 35
Joined: Mon 12 Jan 2009 08:37

Post by JensFudge » Fri 15 Oct 2010 13:41

AndreyZ wrote:You can use the following code:

Code: Select all

Q.FieldByName('Field1').Value := NULL;
oh.. ok.. thanks

Post Reply