Simple DBGrid Problem trying to Null out Foreign Keys 
Author Message
 Simple DBGrid Problem trying to Null out Foreign Keys

Okay,

I have a real simple problem. I am hooking up to the local
interbase server.  I have a table displayed with all it's fields
displayed.

There's a few fields that are actually foreign keys nullable pointing
to another table's primary key.  This is all good until I try to delete
some of these columns.

I try to set certain foreign key records to null by highlighting it, and
hitting backspace.  Instead of having that field get set to null, and
all being good, delphi decides to set it to "".  And interbase
complains about Foreign Key violation constraint errors.

How to I get the DBGrid to default save empty strings into NULL
fields?  Or any other table component for that matter?  In Access,
this is simply a property in the table def. But this is really kicking
my butt, and I imagine this should be a real simple thing...


I'm using Delphi 3, btw.

Jimmy



Wed, 18 Jun 1902 08:00:00 GMT  
 Simple DBGrid Problem trying to Null out Foreign Keys
Okay,

I figured out the problem by reading a related article.  The solution
was to add some code into the event "BeforePost" In the TTable object.
I must have been barking up a tree, as I was looking for a property in the
DBGrid object that would produce this kind of behavior.

for i := 0 to Table1.FieldCount -1 do
   If (Table1.Fields[i].DataType = ftString) then
      If (Table1.Fields[i].AsString = '') then
         Table1.Fields[i].Value := Null;

This just goes through all the columns of the table and sees if they
are empty strings.  If they are, replace them for nulls.

I think this is also a really big problem with OOP.  You gotta have lot's
of good
documentation and even more examples.

Ah well, I ran into yet another problem, but it is unrelated to delphi.
Will post in a separate article.

Jimmy



Quote:
> Okay,

> I have a real simple problem. I am hooking up to the local
> interbase server.  I have a table displayed with all it's fields
> displayed.

> There's a few fields that are actually foreign keys nullable pointing
> to another table's primary key.  This is all good until I try to delete
> some of these columns.

> I try to set certain foreign key records to null by highlighting it, and
> hitting backspace.  Instead of having that field get set to null, and
> all being good, Delphi decides to set it to "".  And interbase
> complains about Foreign Key violation constraint errors.

> How to I get the DBGrid to default save empty strings into NULL
> fields?  Or any other table component for that matter?  In Access,
> this is simply a property in the table def. But this is really kicking
> my butt, and I imagine this should be a real simple thing...


> I'm using Delphi 3, btw.

> Jimmy



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Null values and foreign keys

2. Interbase:Foreign key: null value

3. Replacing a foreign key with its value in a dbgrid

4. Foreign Key problems

5. Foreign keys

6. HOWTO define foreign keys in TTable objects

7. set foreign key at run time --with interbase5.5

8. How to set foreign key to a table on run-time with PARADOX 7

9. how to set foreign key on run-time with PARADOX

10. Interbase Foreign Key question

11. primary and foreign keys

12. Replacing a foreign key ...

 

 
Powered by phpBB® Forum Software