By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,531 Members | 2,219 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,531 IT Pros & Developers. It's quick & easy.

Copying a Record from one DataTable to Another.

P: n/a
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
Feb 20 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Wayne Gibson wrote:
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.

--
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"
Feb 20 '07 #2

P: n/a
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

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.

Feb 20 '07 #3

P: n/a
Wayne Gibson wrote:
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?
--
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"
Feb 20 '07 #4

P: n/a
Normalization ?

"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcomwrote in message
news:u2**************@TK2MSFTNGP06.phx.gbl...
Wayne Gibson wrote:
>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?
--
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"

Feb 20 '07 #5

P: n/a
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.

Wayne Gibson wrote:
Normalization ?

"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcomwrote in message
news:u2**************@TK2MSFTNGP06.phx.gbl...
>Wayne Gibson wrote:
>>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?
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Feb 20 '07 #6

P: n/a
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?

Feb 20 '07 #7

P: n/a

"Wayne Gibson" <wa**********@gmail.comwrote in message
news:er*******************@news.demon.co.uk...
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.
Feb 20 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.