Board index » delphi » !!! help - date query and empty foreign key insertion

!!! help - date query and empty foreign key insertion

hello,
I have two critical questions. I'm using delphi database angine with
paradox tables.

1st Question:
I want to execute that has a date field inside and I don't know how the
date is formatted. For example I want to do something like that:
"UPDATE STUDENTS SET BirthDate=20/07/1970 WHERE StudentID=10".
How is the date formatted? Should I have to include it inside single
quotes ('20/9/1980') or like that #20/9/1980# or how?

2nd Question: When I insert a record with InsertRecord command in Delphi
I have no problem inserting values like '' or nil in fields that are
foreign keys (are used in referential integrity rules and are primary
keys of other tables) when I don't have a value for them yet. So I do
something like this: Table1.InsertRecord([nil, 'teo', '']) where the
third field is a foreign key let's say and the record is inserted
without a value in the third field. BUT when I'm trying to execute an
update query with this kind of fields I CANNOT update the field like
GradeID='' or GradeID=0 because I get an error message "master record
odes not exist"!. But I want to empty this field to contain NO value the
same way I can insert it at first place with no value. How can this been
done when updating a record?

Every answer is higly appreciated,
thanks in advance.

Best regards,
theo

--
Posted via http://dbforums.com

 

Re:!!! help - date query and empty foreign key insertion


Quote
On Tue, 12 Nov 2002 02:56:48 +0000, teooo <mem...@dbforums.com> wrote:

>hello,
>I have two critical questions. I'm using delphi database angine with
>paradox tables.

>1st Question:
>I want to execute that has a date field inside and I don't know how the
>date is formatted. For example I want to do something like that:
>"UPDATE STUDENTS SET BirthDate=20/07/1970 WHERE StudentID=10".
>How is the date formatted? Should I have to include it inside single
>quotes ('20/9/1980') or like that #20/9/1980# or how?

The easist way is to use TDateTime then you don't need to know. Make
the query 'UPDATE STUDENTS SET Birthdate = :Birthdate WHERE StudentID
= :StudentID' then use ParamByName('Birthdate').AsDateTime and
ParamByName('StudentID').AsInteger  to set the values.

Quote

>2nd Question: When I insert a record with InsertRecord command in Delphi
>I have no problem inserting values like '' or nil in fields that are
>foreign keys (are used in referential integrity rules and are primary
>keys of other tables) when I don't have a value for them yet. So I do
>something like this: Table1.InsertRecord([nil, 'teo', '']) where the
>third field is a foreign key let's say and the record is inserted
>without a value in the third field. BUT when I'm trying to execute an
>update query with this kind of fields I CANNOT update the field like
>GradeID='' or GradeID=0 because I get an error message "master record
>odes not exist"!. But I want to empty this field to contain NO value the
>same way I can insert it at first place with no value. How can this been
>done when updating a record?

And what happens to your referential integrity when you do that?

HTH
************************************************************
Ian Jennings
Microware Data Services Limited
This post is made entirely from recycled ones and noughts
************************************************************

Re:!!! help - date query and empty foreign key insertion


thanks for your answer!

nothing happens there is an exception "master record missing" and it
cannot be stored. I want to set the field to be empty not to have a
value, for example student not to have a classid assinged, the classid
field to be totally empty.

I think I made myself clear.

best regards,
theo

--
Posted via http://dbforums.com

Other Threads