473,659 Members | 2,664 Online
Bytes | Software Development & Data Engineering Community
+ 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 3846
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.publi c.dotnet.framew ork.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******@NOyah oo.SPAMcomwrote in message
news:u2******** ******@TK2MSFTN GP06.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******@NOyah oo.SPAMcomwrote in message
news:u2******** ******@TK2MSFTN GP06.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
normalizatio n?
--
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**********@g mail.comwrote in message
news:er******** ***********@new s.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
32347
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 query? 2 - I tried copying them record by record, but the datatype is ntext, (it displays <long
3
2109
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
4563
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 assume that if the datatable and the Access table have the same structure, I can just dump it from one place to the other). I'd be dumping data to the same Access table several times (append). The solution would be like a reverse...
5
1764
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 return a single value. No big deal. But I want to call a Function from another Sub and the function finds and returns an entire db record. Using ASP.NET (VB!), how can this be done and how can I differentiate between the fields/columns? For...
5
2464
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'") temptable.Clear() For Each row As DataRow In temprows temptable.Rows.Add(row) Next
11
1787
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 to be very slow i.e. there are about 100,000 rows of data. Can anybody suggest a quick way to do it? Geoff
6
1397
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 the data and writing a SQL insert command, but there are a ton of fields. It would take forever to get the datatypes correct and the SQL formatted properly. Anyone know how to just copy a record and make a couple changes to it? Thanks Jeff
7
1685
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: public frmSearch(Form1 f)
1
6742
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 passing this dataset to function that expects a dataset with a datatable in it.
0
8427
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8850
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8626
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7355
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4334
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2749
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 we have to send another system
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.