?
Solved

How do you copy records from one table to another?

Posted on 2005-03-07
9
Medium Priority
?
193 Views
Last Modified: 2010-04-16
Hi,

I'd like to copy the entire contents of a table to another table, with the same schema. And I know there must be an easy one line "SELECT * FROM TABLE1" type of command.

Can anybody finish the line above to direct the results to Table2?


Thanks,
Bob
0
Comment
Question by:ba272
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 11

Accepted Solution

by:
sachiek earned 1500 total points
ID: 13482722

ds.Tables[0].Copy() will copy both schema and data to new table.


private void CopyDataSet(DataSet myDataSet){
   // Create an object variable for the copy.
   DataSet copyDataSet;
   copyDataSet = myDataSet.Copy();
   // Insert code to work with the copy.
}

Same case for Table

private void CopyDataTable(DataTable myDataTable){
    // Create an object variable for the copy.
    DataTable copyDataTable;
    copyDataTable = myDataTable.Copy();
    // Insert code to work with the copy.
 }


hope you got it.

Sachi
0
 

Author Comment

by:ba272
ID: 13482770
Hi,

I don't use anyting like what you showed me.  I use SQL commands to handle everything so that it will be portable to other platforms.

I was looking for a "SELECT *" type of command to do the copying.  Do you know it?

Thanks,
Bob
0
 
LVL 11

Expert Comment

by:sachiek
ID: 13482792
Well, That is standard SQL statments.

Above code is by using dataset. That's the difference.

But what is your exact requirement? Do you want it to be done in .net and then insert into SQL Svr or into SQL server using C# directly?


Sachi

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:ba272
ID: 13482845
I have written my entire program using OleDbCommand objects using SQL statements, and this isn't the time for me to learn how to use some new technology.  (I'm just about to reach a deliverable date.)

When I do have the chance, will I get a performance improvement by going that route?

In the meantime, do you know the SQL command?  I think it's:

sql = "SELECT * INTO " + targetTable + " FROM " + sourceTable;


Thanks,
Bob
0
 

Author Comment

by:ba272
ID: 13482864
Sachi,

Thanks for the code.  One day I hope to jump into it.

Bob
0
 
LVL 11

Expert Comment

by:sachiek
ID: 13482884
Ya I knew SQL Command.

So you are building a SQL string then executing that statment.

So sorted out this problem?


Sachi
0
 

Author Comment

by:ba272
ID: 13482901
Yes, I think I got it.  But would I someday benefit by using your approach?  Does it perform better than executing an SQL string?

Thanks,
Bob
0
 
LVL 11

Expert Comment

by:sachiek
ID: 13482928
Well, SQLcommand is much faster. Infact if we use dataset - it will fetch all those records to client side adding more data in viewstate etc etc.

I guess it is good to use SQL Commend which is simple and faster for your requirement.

Sachi
0
 

Author Comment

by:ba272
ID: 13482948
Thanks.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question