473,466 Members | 1,333 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Copying a Record from one DataTable to Another.

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
7 3835
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
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
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
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
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
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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Caroline | last post by:
I need to update a table by copying a column from another table (having the same structure, but on another database), from the record having the same primary key. 1 - What is the correct...
3
by: VM | last post by:
How can I copy the contents of one datatable to another datatable? I've already the source table so I only need to copy its rows. Thanks.
1
by: VMI | last post by:
How can I dump a datatable into an Access table (which contais exactly the same structure)? Somebody suggested doing this with a dataAdapter. I don't want to run an Insert query for each record (I...
5
by: D. Shane Fowlkes | last post by:
This may be a very basic question but it's something I've never done before. I've looked at a couple of my favorite sites and books and can't find an answer either. I can write a Function to...
5
by: Nathan Sokalski | last post by:
I am writing an ASP.NET application in which I need to copy DataRows from one DataTable to another. When I use code such as the following: temprows = nodes.Select("state='PA'")...
11
by: Geoff | last post by:
Hi I have a DataTable with thousands of rows. I want a quick way to insert the rows into a table in an Access database with the same structure. I have been using an update command but found it...
6
by: Jeff Brooks | last post by:
I need to copy a record one access record into the same table. I just need to modify a couple fields that the user will change. Im sure there is an easy way to do it. I have started just reading...
7
by: Hemang Shah | last post by:
I think what i'm trying to do is passing by value. Here is the scenario: Main Form - which calls a Search form. - I pass Mainform as a reference so that I can pass data between the two. Code:...
1
by: tshad | last post by:
Running on VS.net 2005, I am trying to copy rows from my datatable to another datatable in the same dataset. The schema would be identical. I need to make the table name "forms" as I am...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.