Article View: borland.public.interbase.sql
Article #650Re: Insert using TIBDataset and InsertSQL
From: WillR
Date: Thu, 18 Oct 2007 23:39
Date: Thu, 18 Oct 2007 23:39
73 lines
2838 bytes
2838 bytes
dkeene wrote:
> Hi, Folks
> I have used interbase with delphi for a while and I am stuck trying to
> insert a record in a table. MyTable contains a field MID which is a unique
> identifier generated by an appropriate trigger and generator. I am trying to
> insert a blank record using a TIBDataset. I have set the InsertSQL statement
> to
> INSERT INTO MyTable (MID) VALUES (GEN_ID(MyTable_GENERATOR, 1))
>
> Then I open the dataset
> MyDataset.Open;
> MyDataset.Insert;
> MyDataset.Post;
>
> I get the error "Field MID must have a value"
>
> Can anyone suggest the proper way to insert a new record and link the
> Generated number to the field?
>
> Thank you
>
> Doug
insert ibdataset widget on datamodule form (I recommend a dm)
(Name it dm1 for now)
set Database to appropriate db -- presume you have one
set transaction to appropriate transaction -- presume you have one.
Set select (push 3 dots) by SelectSQL property -- just pick a table you
know and use form that pops up to do a "select * from mytable" (change
later if you like...
right click on "mydataset" widget...
(if you get an error message save the datamodule -- sometime it desn't
pick up that you chose a table and set SQL immediately ...)
Choose the dataset editor...
next...
click select primary keys button
click "generate SQL"
click ok
(NOW you can go back and check sql that was automatically generated...
then...
dm1.ib
mydataset.insert
dm1.mydataset.fieldbyname('...').asString; (integer or whatever...)
.
.
.
dm1.mydataset.post
And of course use a transaction to make sure record becomes visible...
There are papers on transactions -- and you _must_ know how to handle them
Look in the examples -- and maybe you should get a Marco Cantu book for
your particular delphi.
--
Will R
PMC Consulting
Technical Details
Message-ID:
<4717ee7d$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!212.101.4.254.MISMATCH!solnet.ch!solnet.ch!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<4717d98a$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 114a0e,f2331f6236805a9 X-Google-Attributes: gid114a0e,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Date: Thu, 18 Oct 2007 19:39:24 -0400 From: WillR <willrNo.Spam.pmccl.noSpam.com> User-Agent: Thunderbird 2.0.0.6 (Windows/20070728) MIME-Version: 1.0 Newsgroups: borland.public.interbase.sql Subject: Re: Insert using TIBDataset and InsertSQL References: <4717d98a$1@newsgroups.borland.com> In-Reply-To: <4717d98a$1@newsgroups.borland.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 99.239.226.34 Message-ID: <4717ee7d$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1192750717 99.239.226.34 (18 Oct 2007 16:38:37 -0700) Lines: 73 Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!212.101.4.254.MISMATCH!solnet.ch!solnet.ch!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail