Article View: borland.public.cppbuilder.database.ado
Article #4744Re: How do I insert a new record into a table with an identity field?
From: BM
Date: Thu, 11 Oct 2001 11:13
Date: Thu, 11 Oct 2001 11:13
62 lines
2763 bytes
2763 bytes
Does your TADOTable have a fields list? If so check the AutoGenerateValue
property of the ID field is set to true and set any other properties which
indicate that its value will be set by the server?
BM
"Andrey Subbotin" <e-ploko@mail.ru> wrote in message
news:3bc2e62f$1_2@dnews...
> Hello all.
>
> How do i insert a new record into a table with an identity field?
> Suppose I have the following piece of code:
>
> TADOTable *t = new TADOTable(FOwnerComponent);
> try {
> t->Connection = FConnection;
> t->TableName = "workers";
> t->Active = true;
> t->Insert();
> t->FieldByName("name")->AsString = "Mr. Incognito";
> t->Post();
> Id = t->FieldByName("id")->AsInteger;
> t->Active = false;
> } __finally {
> delete t;
> }
>
> FOwnerComponent, FConnection and Id are some valid variabled I use in the
> program...
>
> I open the table named "workers". Let it be
>
> table workers (
> id int identity(1,1) not null,
> name varchar(255)
> );
>
> Then assign some name to the "name" field and try to post the changes into
> the DB.
>
> I always supposed that it itsn't necessary to assign some value to
identity
> fields, it's even not possible in plain SQL, AFAIK... And so I hoped that
> the insertion will succeed.
>
> Then, to ruin all my hopes, ADO simply said, "You can't assign NULL value
> to id field. INSERT failed... blah-blah-blah." I know I can't assign NULL,
> or even any other value, to an _identity_ field,
> but ADO thinks I must, and it shouldn't be NULL... Weird.
>
> After all, I'm kind of puzzled. How do I insert a new record into a table
> with an identity field using TADOTable? Is it possible at all?
>
> Any help welcome. Thanks in advice...
>
> See you,
> Andrey.
>
> --- Find out what you can do.
>
>
>
Technical Details
Message-ID:
<3bc58143_2@dnews>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!news.maxwell.syr.edu!news-hog.berkeley.edu!ucberkeley!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!dnewsReferences:
<3bc2e62f$1_2@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10698b,2d119fd5e61bb3cb X-Google-Attributes: gid10698b,public X-Google-ArrivalTime: 2001-10-11 04:25:05 PST From: "BM" <m02x7z00@cwcom.net> Newsgroups: borland.public.cppbuilder.database.ado References: <3bc2e62f$1_2@dnews> Subject: Re: How do I insert a new record into a table with an identity field? Date: Thu, 11 Oct 2001 12:13:34 +0100 Lines: 64 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2919.6600 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6600 NNTP-Posting-Host: 212.137.161.150 Message-ID: <3bc58143_2@dnews> X-Trace: dnews 1002799427 212.137.161.150 (11 Oct 2001 04:23:47 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!news.maxwell.syr.edu!news-hog.berkeley.edu!ucberkeley!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!dnews