Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Database and Reporting > Copy / Archive DB table


Reply
 
Thread Tools Display Modes
  #1  
Old 04-11-2003, 02:19 PM
ArmyBoy ArmyBoy is offline
Newcomer
 
Join Date: Jan 2003
Posts: 17
Default Copy / Archive DB table


Hi, I got a table CustomerInfo. I want to copy/archive the records in it to another table CustomerHistory.

I have to do it thru VB. And I'm using ADODC. The source of connection is Data Link File.

Any idea how i can do it?

Thanks! URGENT.........
Reply With Quote
  #2  
Old 04-11-2003, 03:38 PM
loquin's Avatar
loquin loquin is offline
Google Hound

Retired Moderator
* Guru *
 
Join Date: Nov 2001
Location: Arizona, USA
Posts: 12,378
Default

The simplest way would be to NOT use the data control, establish a data connection through code, and issue a SQL command to the database to have IT insert the records into the CustomerHistory table from the CustomerInfo table.

Code:
Dim cnDB as Adodb.Connection Set cnDB = new Adodb.Connection cnDB.Open YourConnectionString cnDB.Execute "Insert into CustomerHistory Select * From CustomerInfo" cnDB.Close set cnDB = nothing
__________________
Lou
"I have my standards. They may be low, but I have them!" ~ Bette Middler
"It's a book about a Spanish guy called Manual. You should read it." ~ Dilbert
"To understand recursion, you must first understand recursion." ~ unknown
Reply With Quote
  #3  
Old 04-11-2003, 07:02 PM
ArmyBoy ArmyBoy is offline
Newcomer
 
Join Date: Jan 2003
Posts: 17
Default

Thanks loquin! But is there no way to do it using the data control? Cos i really have to use it.
Reply With Quote
  #4  
Old 04-11-2003, 09:14 PM
loquin's Avatar
loquin loquin is offline
Google Hound

Retired Moderator
* Guru *
 
Join Date: Nov 2001
Location: Arizona, USA
Posts: 12,378
Default

Is there a reason that you must use the data control? because the only reason that I could think of for a requirement of using something as ineffecient as the data control is for homework.
__________________
Lou
"I have my standards. They may be low, but I have them!" ~ Bette Middler
"It's a book about a Spanish guy called Manual. You should read it." ~ Dilbert
"To understand recursion, you must first understand recursion." ~ unknown
Reply With Quote
  #5  
Old 04-11-2003, 11:46 PM
ArmyBoy ArmyBoy is offline
Newcomer
 
Join Date: Jan 2003
Posts: 17
Default

Haha! You are definitely right loquin.

But it is also because I need the ADODC so that I can use the Data Link File. I'll use ur codes if no other way.
Reply With Quote
  #6  
Old 04-12-2003, 03:59 AM
ArmyBoy ArmyBoy is offline
Newcomer
 
Join Date: Jan 2003
Posts: 17
Default

Loquin, ur code worked great! thanks again

But now I have another problem....

Say if I need to insert records whose entry date is today, how can i do it? This is what i've tried in addition to ur code.

Dim Today As Date
.........
.........
cnDB.Execute "INSERT INTO CusHistory SELECT * FROM CusInfo WHERE cus_date = Today"

The cus_date is a field in a Access Database table with Data Type Date/Time.

I keep getting the error num -2147217904 which says "No value given for one or more parameters"

What's the problem???..........

Last edited by ArmyBoy; 04-12-2003 at 04:13 AM.
Reply With Quote
  #7  
Old 04-12-2003, 04:59 AM
ArmyBoy ArmyBoy is offline
Newcomer
 
Join Date: Jan 2003
Posts: 17
Default

haha solved!

nsDB.Execute "INSERT INTO NoShows SELECT * FROM Reservation WHERE arr_date = #" & Format(Now, "mm/dd/yyyy") & "#"
Reply With Quote
  #8  
Old 04-12-2003, 01:04 PM
Thinker Thinker is offline
Iron-Fisted Programmer

Retired Moderator
* Guru *
 
Join Date: Jul 2001
Location: Fayetteville Arkansas USA
Posts: 18,127
Default

There is no requirement to use the ADO datacontrol just to use a data-
link file. In fact there is no requirement to use a data-link file anyway,
but if you insist on using it, you can specify it as the ConnectionString
for a Connection object using...
Code:
Dim cnDB As ADODB.Connection Set cnDB = New ADODB.Connection cnDB.ConnectionString = "File Name=" & App.Path & "\mydatalink.udl" cnDB.Open
__________________
Posting Guidelines
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy records from one table to another in VB leadwick Database and Reporting 5 06-19-2002 09:10 PM
how can i quickly copy one table to another? plz read redi6 Database and Reporting 2 06-19-2002 09:35 AM
Hekp Importing Excel JonM Word, PowerPoint, Outlook, and Other Office Products 2 05-01-2002 09:45 AM
got a way to copy db table structure at runtime angelbear Database and Reporting 5 01-30-2002 06:37 PM
Table Copy ricgre Database and Reporting 3 07-11-2001 11:44 PM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->