Copying a Record from one DataTable to Another.

W

Wayne Gibson

Hi All,
Was wondering if anybody could help. I'm currently trying to copy a record
from datatable to another. I have two problems:

1) Transferring the record from one datatable to another.
2) Transferring the record from the new datatable back to the database.

Any ideas?

Thanks

Gibbo
 
B

Bob Barrows [MVP]

Wayne said:
Hi All,
Was wondering if anybody could help. I'm currently trying to copy a
record from datatable to another. I have two problems:

1) Transferring the record from one datatable to another.
2) Transferring the record from the new datatable back to the
database.
Any ideas?
First of all, this is an ADO.Net question so you should not have crossposted
it to .data.ado which is a classic ado group. The relevant dotnet group is
microsoft.public.dotnet.framework.adonet.
As for your question, I'm not sure I understand the problem. Isn't it just a
matter of cloning the relevant datarow and appending it to the Rows
collection of the other datatable (assuming the schema is the same of course
.... ). Then sync the datatable with the database the same way you normally
would after doing an update to the datatable.
 
W

Wayne Gibson

Hi Bob,
thanks for replying.. Sorry for cross posting, but wasn't sure which group
to post to...

Anyway...

The databases will look something like this:
Database1.MDB
Table1
fields (Won't know what these are at runtime)

Database2.MDB
Table1
fields (Won't know what these are at runtime)
ExtraField (Will know what this is at runtime)

I'm using a datareader to read an Access Table, using a "Select * from
TableName". I have no idea of what the structure of the table is, so this
is why it is being read into a datatable.
The destination table is exactly the same, except it would have an extra
field. Which I can update separately.
I could clone the datarow, which isn't a problem. The problem is
updating/inserting the row into the destination table. Am I right in
thinking that I would need to create the SQL Query to do this, by reading
the schema for the table to get the field names and types. Then execute it.
Or is there a simpler way of doing this..

Many thanks
 
B

Bob Barrows [MVP]

Wayne said:
updating/inserting the row into the destination table. Am I right in
thinking that I would need to create the SQL Query to do this, by
reading the schema for the table to get the field names and types. Then
execute it.
That's how I would do it.

ISTM there is too much of this "schema not known at design-time" business
here. Could your database(s) maybe benefit from some normalization?
 
W

Wayne Gibson

Normalization ?

Bob Barrows said:
That's how I would do it.

ISTM there is too much of this "schema not known at design-time" business
here. Could your database(s) maybe benefit from some normalization?
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
 
B

Bob Barrows [MVP]

As the old joke goes: "if you have to ask, then you can't afford it". In
this case, "if you have to ask, then you could probably benefit from it"
;-)

Do a google search for "database normalization" - it's too broad a topic
for a newsgroup message.
 
W

Wayne Gibson

Thanks, now understand what you are talking about regarding normalisation.

This doesn't apply in my case. This is for an application that I hope to
reuse for several projects. The purpose is to compare and sync data between
access databases. So the structures will change from one project to the
next. Then to sync the data to a SQL server at some point.

So looks like I'll have to create an Update & Insert SQL string each record
that has been changed/added :(

Any other suggestions?
 
R

RobinS

Wayne Gibson said:
Thanks, now understand what you are talking about regarding
normalisation.

This doesn't apply in my case. This is for an application that I hope to
reuse for several projects. The purpose is to compare and sync data
between access databases. So the structures will change from one project
to the next. Then to sync the data to a SQL server at some point.

So looks like I'll have to create an Update & Insert SQL string each
record that has been changed/added :(

Any other suggestions?

You could read the data from one table and write it to another row by row.
Think of it as the "brute force" method. Queries would be faster.

Robin S.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top