Thread View: borland.public.delphi.database.dotnet
2 messages
2 total messages
Started by Brigitte Spatz
Mon, 06 Nov 2006 15:09
copying a record
Author: Brigitte Spatz
Date: Mon, 06 Nov 2006 15:09
Date: Mon, 06 Nov 2006 15:09
20 lines
1585 bytes
1585 bytes
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;
TIA.
Brigitte
Re: copying a record
Author: 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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads