BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Null value assign to Parameter

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (ADO)
View previous topic :: View next topic  
Author Message
Alan T
Guest





PostPosted: Wed Mar 14, 2007 8:11 am    Post subject: Null value assign to Parameter Reply with quote



I have a table of Employee:
ID
Name
JoinedDate
LeftDate

I got an exception when I move the Employee details to another table if the
LeftDate in Employee table is null.
I use
Parameters.ParamByName('...').Value to assign the value.
I assume if the value is null, then it will assign null value to the
paramete but it's not.


Query2.Close;
Query2.SQL.Clear;
Query2.SQL.Add('INSERT INTO Staff (ID,Name,JoinedDate, LeftDate) ' +
'VALUES (:ID,:Name,:JoinedDate,:LeftDate)');

with Query1 do
begin
Close;
SQL.Clear;
SQL.Add('SELECT * from Employee');
Open;
First;
while not eof do
begin
Query2.Close;
Query2.Parameters.ParamByName('ID').Value := FieldByName('ID').Value;
Query2.Parameters.ParamByName('Name').Value :=
FieldByName('Name').Value;
Query2.Parameters.ParamByName('JoinedDate').Value :=
FieldByName('JoinedDate').Value;
// exception happened below if the FieldByName('LeftDate') is null
Query2.Parameters.ParamByName('LeftDate').Value :=
FieldByName('LeftDate').Value;
Query2.ExecSQL;
Next;
end;
end;
Back to top
Helmut Woess
Guest





PostPosted: Wed Mar 14, 2007 8:11 am    Post subject: Re: Null value assign to Parameter Reply with quote



Am Wed, 14 Mar 2007 17:31:58 +1100 schrieb Alan T:

....
Quote:
I use
Parameters.ParamByName('...').Value to assign the value.
I assume if the value is null, then it will assign null value to the
paramete but it's not.

I know this problem too and can't explain why this happens. But i learned
to write assignments using "value" always in this way:
....
if FieldByName('LeftDate').IsNull then
Query2.Parameters.ParamByName('LeftDate').Clear
else Query2.Parameters.ParamByName('LeftDate').Value :=
FieldByName('LeftDate').Value;
....

bye,
Helmut
Back to top
Alan T
Guest





PostPosted: Mon Apr 23, 2007 8:11 am    Post subject: Re: Null value assign to Parameter Reply with quote



Hi,

I cannot the Method or Property called Clear.

"Helmut Woess" <user22 (AT) inode (DOT) at> wrote in message
news:bgizs7prj44k$.1iiufq2n7fku5$.dlg (AT) 40tude (DOT) net...
Quote:
Am Wed, 14 Mar 2007 17:31:58 +1100 schrieb Alan T:

...
I use
Parameters.ParamByName('...').Value to assign the value.
I assume if the value is null, then it will assign null value to the
paramete but it's not.

I know this problem too and can't explain why this happens. But i learned
to write assignments using "value" always in this way:
...
if FieldByName('LeftDate').IsNull then
Query2.Parameters.ParamByName('LeftDate').Clear
else Query2.Parameters.ParamByName('LeftDate').Value :=
FieldByName('LeftDate').Value;
...

bye,
Helmut
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (ADO) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.