Article View: borland.public.delphi.database.dotnet
Article #2Re: copying a record
From: Brigitte Spatz
Date: Tue, 07 Nov 2006 13:02
Date: Tue, 07 Nov 2006 13:02
44 lines
2802 bytes
2802 bytes
Brigitte Spatz wrote:
> What is the correct way to copy a record? I've tried
>
> var
> dr: DataRow;
> i: Integer;
> begin
> dr := dv.Item[bm.Position].Row; {dv = Dataview, bm = BindingManagerBase}
> for i := 0 to Length(arrComp) - 1 do //arrComp = array of Integer
> begin
> bm.AddNew;
> dv.Item[bm.Position].Row.ItemArray := dr.ItemArray;
> dv.Item[bm.Position].Row.Item['fld_company'] := arrComp[i];
> bm.EndCurrentEdit; //this doesn't work, gives "no value at index 8"
> db.write_changes_ins(da, ds, true, 'ODM', sqlInsertCommand1);
> end;
> dv.AllowNew := False;
Further experiments have shown that the BindingManager is the culprit:
The task is to copy one record from one client to another. The datatable
holds the data for all clients but the dataview has a filter applied
that shows only the currently selected client's records, and the same
obviously applies to the binding manager. Now since the new record has a
client number that doesn't fit the row filter criterion of the dataview,
it will not be displayed in the datagrid, so bm.addnew will not result
in an increase of bm.position and it all goes pearshaped from then on.
I've now tried
dr := dv.Item[bm.Position].Row;
dr.Item['fld_company'] := arrComp[0];
ds.Tables['ODM'].Rows.Add(dr);
but that only results in an error message telling me that dr is already
part of the ODM table, which is probably because the ID hasn't been
updated. If I add an ordinary record I can use the sqlInsertCommand,
which calls a stored procedure in SQL Server that has an InOut identity
parameter to get the ID but that would require bm.position, so I'm back
at square one.
So what else could I try?
TIA.
Brigitte
Technical Details
Message-ID:
<455083e5@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!news.glorb.com!solnet.ch!solnet.ch!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<454f502b@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 1effe6,1ccf0ad458ca5df4 X-Google-Attributes: gid1effe6,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Tue, 07 Nov 2006 14:02:27 +0100 From: Brigitte Spatz <brigitteNOSPAM.spatz@svenmahn.de> Organization: Sven Mahn IT-Systementwicklungen User-Agent: Thunderbird 1.5.0.7 (Windows/20060909) MIME-Version: 1.0 Newsgroups: borland.public.delphi.database.dotnet Subject: Re: copying a record References: <454f502b@newsgroups.borland.com> In-Reply-To: <454f502b@newsgroups.borland.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Antivirus: avast! (VPS 0646-0, 06/11/2006), Outbound message X-Antivirus-Status: Clean NNTP-Posting-Host: 217.189.171.33 Message-ID: <455083e5@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1162904549 217.189.171.33 (7 Nov 2006 05:02:29 -0700) Lines: 44 Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!news.glorb.com!solnet.ch!solnet.ch!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail