Board index » delphi » copying record from one table to another

copying record from one table to another

How can I copy a record from one table to another? I'm using Paradox tables,
accessed through an Alias.
I need to copy one record to a temporary table, edit some fields, and then
append the record to the original table.
The record in the original table has to be deleted.

Richard

 

Re:copying record from one table to another


tBatchMove Component should do what you need.

Quote
"Richard" <rvann...@wanadoo.nl> wrote in message news:3b8aad71_2@dnews...
> How can I copy a record from one table to another? I'm using Paradox
tables,
> accessed through an Alias.
> I need to copy one record to a temporary table, edit some fields, and then
> append the record to the original table.
> The record in the original table has to be deleted.

> Richard

Re:copying record from one table to another


But how can I make it so that TBatchMove only copys the one and only
selected record?
Which option do I have to use?

Quote
"Carl Alyea" <Carl.J.Al...@fhwa.dot.gov> wrote in message

news:3b8ab9a7$1_2@dnews...
Quote
> tBatchMove Component should do what you need.

> "Richard" <rvann...@wanadoo.nl> wrote in message news:3b8aad71_2@dnews...
> > How can I copy a record from one table to another? I'm using Paradox
> tables,
> > accessed through an Alias.
> > I need to copy one record to a temporary table, edit some fields, and
then
> > append the record to the original table.
> > The record in the original table has to be deleted.

> > Richard

Re:copying record from one table to another


Use the onFilter event and filter for the one you want.
Quote
Richard wrote:
> But how can I make it so that TBatchMove only copys the one and only
> selected record?
> Which option do I have to use?

> "Carl Alyea" <Carl.J.Al...@fhwa.dot.gov> wrote in message
> news:3b8ab9a7$1_2@dnews...
> > tBatchMove Component should do what you need.

> > "Richard" <rvann...@wanadoo.nl> wrote in message news:3b8aad71_2@dnews...
> > > How can I copy a record from one table to another? I'm using Paradox
> > tables,
> > > accessed through an Alias.
> > > I need to copy one record to a temporary table, edit some fields, and
> then
> > > append the record to the original table.
> > > The record in the original table has to be deleted.

> > > Richard

Re:copying record from one table to another


To copy a single record use two TTables and:

for I := 0 to SourceTable.FieldCount - 1 do
  DestTable.Fields[I].Assign(SourceTable.Fields[I]);

--
Bill
(TeamB cannot answer questions received via email)

Re:copying record from one table to another


Quote
"Richard" <rvann...@wanadoo.nl> wrote in message news:3b8aad71_2@dnews...
> How can I copy a record from one table to another? I'm using Paradox
tables,
> accessed through an Alias.
> I need to copy one record to a temporary table, edit some fields, and then
> append the record to the original table.
> The record in the original table has to be deleted.

What's different about this than editing the record in place in the original
table?

You can use a query to do thi:

Insert into temptable
select * from origtable
where auniquekey = somevalue;

--
Wayne Niddery (Logic Fundamentals, Inc.)
RADBooks: http://www.logicfundamentals.com/RADBooks/delphibooks.html
"Some see private enterprise as a predatory target to be shot, others as a
cow to be milked, but few are those who see it as a sturdy horse pulling the
wagon." - Winston Churchill

Re:copying record from one table to another


I don't just want to edit the record, I want to duplicate it. But before I
add the record to the table where the original record resides, I need to
change two fields (to prevent I get duplicate records).
And how kan I use a string-variable in my SQL-syntax (thus something like
this: WHERE MyID = strVariable)

Richard

"Wayne Niddery [TeamB]" <wnidd...@aci.on.ca> wrote in message
news:3b8aefa9_2@dnews...

Quote
> "Richard" <rvann...@wanadoo.nl> wrote in message news:3b8aad71_2@dnews...
> > How can I copy a record from one table to another? I'm using Paradox
> tables,
> > accessed through an Alias.
> > I need to copy one record to a temporary table, edit some fields, and
then
> > append the record to the original table.
> > The record in the original table has to be deleted.

> What's different about this than editing the record in place in the
original
> table?

> You can use a query to do thi:

> Insert into temptable
> select * from origtable
> where auniquekey = somevalue;

> --
> Wayne Niddery (Logic Fundamentals, Inc.)
> RADBooks: http://www.logicfundamentals.com/RADBooks/delphibooks.html
> "Some see private enterprise as a predatory target to be shot, others as a
> cow to be milked, but few are those who see it as a sturdy horse pulling
the
> wagon." - Winston Churchill

Re:copying record from one table to another


Instead of using two tables your could:

1) Copy the record to a variant array, change the fields, insert a new
record and copy the values from the array to the new record.

2) Use two TTables connected to the same database table. Postion one TTable
on the record you want to copy. Insert a new record in the second TTable.
Copy the field values from one to the other using the for loop in my
previous message. Change the values of the fields that need to be changed
before you post the new record.

--
Bill
(TeamB cannot answer questions received via email)

Re:copying record from one table to another


Quote
"Richard" <rvann...@wanadoo.nl> wrote in message news:3b8b5ca3_1@dnews...
> And how kan I use a string-variable in my SQL-syntax (thus something like
> this: WHERE MyID = strVariable)

Two ways.
1) Formatting the string:
Query1.SQl.Add('Insert into temptable');
Query1.SQl.Add('select * from origtable');
Query1.SQl.Add('where auniquekey = ' + QuotedStr(somestringvar));
Query1.ExecSQL;

2) Parameterized query (preferred if this statement is going to be executed
often):

Query1.SQl.Add('Insert into temptable');
Query1.SQl.Add('select * from origtable');
Query1.SQl.Add('where auniquekey = :uniquekey');

Do the above once or better, just set the SQL in the TQuery at design-time.
Then whenever you need to execute it just set the parameter:

Query1.Params[0].AsString := somestringvar;
Query1.ExecSQL;

--
Wayne Niddery (Logic Fundamentals, Inc.)
RADBooks: http://www.logicfundamentals.com/RADBooks/delphibooks.html
"Some see private enterprise as a predatory target to be shot, others as a
cow to be milked, but few are those who see it as a sturdy horse pulling the
wagon." - Winston Churchill

Other Threads