 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Alan T Guest
|
Posted: Wed Mar 14, 2007 8:11 am Post subject: Null value assign to Parameter |
|
|
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
|
Posted: Wed Mar 14, 2007 8:11 am Post subject: Re: Null value assign to Parameter |
|
|
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
|
Posted: Mon Apr 23, 2007 8:11 am Post subject: Re: Null value assign to Parameter |
|
|
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 |
|
 |
|
|
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
|
|