Board index » delphi » Last Time : 'Losing Key Column Information'

Last Time : 'Losing Key Column Information'

        This is the third time that I ask this question. I just wonder if I
am the only one who gets this problem as a result of making mistake or
someone else gets the same.
        I also wonder that although the problem seems so simple (explained
below),  can not anyone say this is my mistake or a bug in TADODataSet or in
somewhere else in the Ado package or in SQL Server??? .
        Hope to hear someone saying I am in mistake or I shouldn't try what
I do or anything else ...

        I use Delphi 5 with update pack installed and SQL Server 7.0

    thanks in advance...

Quote
>         A problem (bug or some mistake)  occured using TADODataSet. I
asked
> this problem to this newsgroup earlier, but no reply has come out. Hope to
> get a way out this time.

>         The problem is the following (so simple to explain) :,

>             When opening an ADODataSet object, If there is another
> active(opened) ADODataSet object using the same ADOConnection object, the
> former dataset object loses the key column information. Therefore the
> fields', which are key fields, Properties.Item[4].Value property becomes 0
> (meaning that this is not a KEY Field).

>             However, if there is no active dataset (using the same
> connection object) before the dataset is opened, the key fields have true
> key field information.

>             Ex: {Assume that first fields are key fields in both dataset
and
> both dataset objects use the same connection }

>                 flag1 : Boolean ;
>                 flag2 : Boolean;

>                 ADODataSet1.Open;
>                 ADODataSet2.Open;

>                 flag1 :=
> Boolean(ADODataSet1.RecordSet.Fields[0].Properties.Item[4].Value);
>                 flag2 :=
> Boolean(ADODataSet2.RecordSet.Fields[0].Properties.Item[4].Value);
> (*
>                Result obtained :
>                      flag1 is TRUE,
>                      flag2 is FALSE.... ???? !!!!....
> *)

>                 ADODataSet1.Close;
>                 ADODataSet2.Close;

>                 (* Change the order of opening datasets *)
>                 ADODataSet2.Open;
>                 ADODataSet1.Open;

>                 flag1 :=
> Boolean(ADODataSet1.RecordSet.Fields[0].Properties.Item[4].Value);
>                 flag2 :=
> Boolean(ADODataSet2.RecordSet.Fields[0].Properties.Item[4].Value);

> (*
>                Result obtained :
>                      flag1 is FALSE,
>                      flag2 is TRUE.... ???? !!!!....
> *)

 

Re:Last Time : 'Losing Key Column Information'


Hi Erdem,

Quote
> > fields', which are key fields, Properties.Item[4].Value property becomes 0
> > ....
> >                 flag1 :=
> > Boolean(ADODataSet1.RecordSet.Fields[0].Properties.Item[4].Value);

You have got that wrong. The RecordSet.Fields[0] is a reference to an
ADO Field object. The Field.Properties collection does not have a property
indicating which fields are index members. Instead you should use the
Field.Attributes (Long) property for the purpose. Check against the following
enum value:

    adFldKeyColumn    ($8000)
    Indicates that the field is the primary key of the underlying rowset.
    Also can indicate that the field is part of a compound primary key.

So you should try the folowing:
    flag1 :=
    (ADODataSet1.RecordSet.Fields[0].Attributes AND
    adFldKeyColumn = adFldKeyColumn)

Also you should rather use
    Properties.Item['NameOfItem'].Value
instead of
    Properties.Item[4].Value.
Using the Name rather than
the numeric value of the constant or index might have saved you
and me quite some time ;-)

HTH
--
V. Nazarov
IT Manager, Sofia Cable

Quote
"Erdem Gunay" <erdem_gu...@hotmail.com> wrote in message

news:8g3173$b3j3@bornews.borland.com...
Quote

>         This is the third time that I ask this question. I just wonder if I
> am the only one who gets this problem as a result of making mistake or
> someone else gets the same.
>         I also wonder that although the problem seems so simple (explained
> below),  can not anyone say this is my mistake or a bug in TADODataSet or in
> somewhere else in the Ado package or in SQL Server??? .

>         Hope to hear someone saying I am in mistake or I shouldn't try what
> I do or anything else ...

>         I use Delphi 5 with update pack installed and SQL Server 7.0

>     thanks in advance...

> >         A problem (bug or some mistake)  occured using TADODataSet. I
> asked
> > this problem to this newsgroup earlier, but no reply has come out. Hope to
> > get a way out this time.

> >         The problem is the following (so simple to explain) :,

> >             When opening an ADODataSet object, If there is another
> > active(opened) ADODataSet object using the same ADOConnection object, the
> > former dataset object loses the key column information. Therefore the
> > fields', which are key fields, Properties.Item[4].Value property becomes 0
> > (meaning that this is not a KEY Field).

> >             However, if there is no active dataset (using the same
> > connection object) before the dataset is opened, the key fields have true
> > key field information.

> >             Ex: {Assume that first fields are key fields in both dataset
> and
> > both dataset objects use the same connection }

> >                 flag1 : Boolean ;
> >                 flag2 : Boolean;

> >                 ADODataSet1.Open;
> >                 ADODataSet2.Open;

> >                 flag1 :=
> > Boolean(ADODataSet1.RecordSet.Fields[0].Properties.Item[4].Value);
> >                 flag2 :=
> > Boolean(ADODataSet2.RecordSet.Fields[0].Properties.Item[4].Value);
> > (*
> >                Result obtained :
> >                      flag1 is TRUE,
> >                      flag2 is FALSE.... ???? !!!!....
> > *)

> >                 ADODataSet1.Close;
> >                 ADODataSet2.Close;

> >                 (* Change the order of opening datasets *)
> >                 ADODataSet2.Open;
> >                 ADODataSet1.Open;

> >                 flag1 :=
> > Boolean(ADODataSet1.RecordSet.Fields[0].Properties.Item[4].Value);
> >                 flag2 :=
> > Boolean(ADODataSet2.RecordSet.Fields[0].Properties.Item[4].Value);

> > (*
> >                Result obtained :
> >                      flag1 is FALSE,
> >                      flag2 is TRUE.... ???? !!!!....
> > *)

Re:Last Time : 'Losing Key Column Information'


This works, thank you so much.

I am sorry for  Properties.Item[4].Value :-)

-Erdem.

Quote
Vassil Nazarov <s...@bulnet.bg> wrote in message news:392551f2@dnews...
> Hi Erdem,

> > > fields', which are key fields, Properties.Item[4].Value property
becomes 0
> > > ....
> > >                 flag1 :=
> > > Boolean(ADODataSet1.RecordSet.Fields[0].Properties.Item[4].Value);

> You have got that wrong. The RecordSet.Fields[0] is a reference to an
> ADO Field object. The Field.Properties collection does not have a property
> indicating which fields are index members. Instead you should use the
> Field.Attributes (Long) property for the purpose. Check against the
following
> enum value:

>     adFldKeyColumn    ($8000)
>     Indicates that the field is the primary key of the underlying rowset.
>     Also can indicate that the field is part of a compound primary key.

> So you should try the folowing:
>     flag1 :=
>     (ADODataSet1.RecordSet.Fields[0].Attributes AND
>     adFldKeyColumn = adFldKeyColumn)

> Also you should rather use
>     Properties.Item['NameOfItem'].Value
> instead of
>     Properties.Item[4].Value.
> Using the Name rather than
> the numeric value of the constant or index might have saved you
> and me quite some time ;-)

> HTH
> --
> V. Nazarov
> IT Manager, Sofia Cable

> "Erdem Gunay" <erdem_gu...@hotmail.com> wrote in message
> news:8g3173$b3j3@bornews.borland.com...

> >         This is the third time that I ask this question. I just wonder
if I
> > am the only one who gets this problem as a result of making mistake or
> > someone else gets the same.
> >         I also wonder that although the problem seems so simple
(explained
> > below),  can not anyone say this is my mistake or a bug in TADODataSet
or in
> > somewhere else in the Ado package or in SQL Server??? .

> >         Hope to hear someone saying I am in mistake or I shouldn't try
what
> > I do or anything else ...

> >         I use Delphi 5 with update pack installed and SQL Server 7.0

> >     thanks in advance...

> > >         A problem (bug or some mistake)  occured using TADODataSet. I
> > asked
> > > this problem to this newsgroup earlier, but no reply has come out.
Hope to
> > > get a way out this time.

> > >         The problem is the following (so simple to explain) :,

> > >             When opening an ADODataSet object, If there is another
> > > active(opened) ADODataSet object using the same ADOConnection object,
the
> > > former dataset object loses the key column information. Therefore the
> > > fields', which are key fields, Properties.Item[4].Value property
becomes 0
> > > (meaning that this is not a KEY Field).

> > >             However, if there is no active dataset (using the same
> > > connection object) before the dataset is opened, the key fields have
true
> > > key field information.

> > >             Ex: {Assume that first fields are key fields in both
dataset
> > and
> > > both dataset objects use the same connection }

> > >                 flag1 : Boolean ;
> > >                 flag2 : Boolean;

> > >                 ADODataSet1.Open;
> > >                 ADODataSet2.Open;

> > >                 flag1 :=
> > > Boolean(ADODataSet1.RecordSet.Fields[0].Properties.Item[4].Value);
> > >                 flag2 :=
> > > Boolean(ADODataSet2.RecordSet.Fields[0].Properties.Item[4].Value);
> > > (*
> > >                Result obtained :
> > >                      flag1 is TRUE,
> > >                      flag2 is FALSE.... ???? !!!!....
> > > *)

> > >                 ADODataSet1.Close;
> > >                 ADODataSet2.Close;

> > >                 (* Change the order of opening datasets *)
> > >                 ADODataSet2.Open;
> > >                 ADODataSet1.Open;

> > >                 flag1 :=
> > > Boolean(ADODataSet1.RecordSet.Fields[0].Properties.Item[4].Value);
> > >                 flag2 :=
> > > Boolean(ADODataSet2.RecordSet.Fields[0].Properties.Item[4].Value);

> > > (*
> > >                Result obtained :
> > >                      flag1 is FALSE,
> > >                      flag2 is TRUE.... ???? !!!!....
> > > *)

Other Threads