PC Review


Reply
Thread Tools Rate Thread

Copying a Record from one DataTable to Another.

 
 
Wayne Gibson
Guest
Posts: n/a
 
      20th Feb 2007
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


 
Reply With Quote
 
 
 
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      20th Feb 2007
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"


 
Reply With Quote
 
Wayne Gibson
Guest
Posts: n/a
 
      20th Feb 2007
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.



 
Reply With Quote
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      20th Feb 2007
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"


 
Reply With Quote
 
Wayne Gibson
Guest
Posts: n/a
 
      20th Feb 2007
Normalization ?

"Bob Barrows [MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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"
>



 
Reply With Quote
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      20th Feb 2007
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]" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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.


 
Reply With Quote
 
Wayne Gibson
Guest
Posts: n/a
 
      20th Feb 2007
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?



 
Reply With Quote
 
RobinS
Guest
Posts: n/a
 
      20th Feb 2007

"Wayne Gibson" <(E-Mail Removed)> wrote in message
news:erf7ca$cup$1$(E-Mail Removed)...
> 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copying records from datatable to datatable in dataset tshad Microsoft C# .NET 1 24th Jun 2008 01:39 AM
Copying a Record from one DataTable to Another. Wayne Gibson Microsoft ADO .NET 4 22nd Feb 2007 11:17 PM
Copying a Record from one DataTable to Another. Wayne Gibson Microsoft Dot NET Framework Forms 7 20th Feb 2007 05:01 PM
Copying datatable contents to another datatable VM Microsoft C# .NET 3 14th Jul 2004 07:31 PM
Q: copying a datatable Geoff Jones Microsoft VB .NET 2 29th Jun 2004 03:54 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:31 AM.