473,407 Members | 2,315 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

How to move table data in one server to another server

Hi,
I need to move one table in one server(Live) to another server(Development) through Visual basic coding. Please send soultion for this
Feb 9 '07 #1
3 4968
dorinbogdan
839 Expert 512MB
Supposing that the table exists on the destination database:

Private Function ExportTable(tbl as String)


End Function
Feb 9 '07 #2
dorinbogdan
839 Expert 512MB
I'm sorry for the previous incomplete message.
I'll write a sample code in few moments...
Feb 9 '07 #3
dorinbogdan
839 Expert 512MB
The solution I suggest is to use 2 ADODB.Recordset objects, and 2 ADODB.Connection objects (it requires to add a reference to Microsoft ActiveX Data Objects in Project/References)
You just have to update the connection strings strConn1 and strConn2.
(I couldn't check the code, since I don't have VB6 installed).
Don't forget to create the destination table with same structure as source table.

Expand|Select|Wrap|Line Numbers
  1. Private Function ExportTable(strTable As String) 
  2. Dim i As Integer
  3. Dim rs1 As Object 'ADODB.Recordset
  4. Dim rs2 As Object 'ADODB.Recordset
  5. Dim cn1 As Object 'ADODB.Connection
  6. Dim cn2 As Object 'ADODB.Connection
  7. Dim strConn1 As String
  8. Dim strConn2 As String
  9. On Error Goto EH
  10.     ExportTable = False
  11.     strConn1 = "Driver={SQL Server};Server=Live;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
  12.     strConn2 = "Driver={SQL Server};Server=Development;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
  13.     set cn1 = CreateObject("ADODB.Connection")
  14.     set cn2 = CreateObject("ADODB.Connection")
  15.     set rs1 = CreateObject("ADODB.Recordset")
  16.     set rs2 = CreateObject("ADODB.Recordset")
  17.     cn1.Open  strConn1
  18.     cn2.Open  strConn2
  19.  
  20.     rs1.Open "Select * From " & strTable , cn1, adOpenStatic, adLockReadOnly
  21.     rs2.Open "Select top 0 * From " & strTable , cn2, adOpenDynamic, adLockPessimistic
  22.     rs1.MoveFirst
  23.     If Not (rs1.EOF and rs1.BOF) Then  
  24.         While not rs1.EOF
  25.             rs2.AddNew
  26.             For i = 0 to rs1.Fields.Count-1
  27.                 rs2.Fields(i) = rs1.Fields(i) 
  28.             Next
  29.             rs2.Update
  30.             rs1.MoveNext 
  31.         Wend
  32.     End If
  33.     rs1.Close
  34.     rs2.Close
  35.  
  36.     ExportTable = True
  37.  
  38. EH:
  39.     MsgBox Err.Number & ": " & Err.Description 
  40. End Function
  41.  
Feb 9 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: CPNZ | last post by:
I have a database i am m oving to another server, during the process I am moving the data and log files to another drive.(Which I have done countless times before with no problems) The problem I...
7
by: tshad | last post by:
Is there a way to move a row in a Datalist up or down without having to re-read the data? I have a datalist which has embedded Datagrids in it. I want to allow the user to move a row up or down...
5
by: Tim | last post by:
Hi, I am trying to move a datacolumn in a datatable. What I have tried so far is to create a new datacolumn set it equal to the one I want to remove and then remove it, add another column and...
10
by: Robert | last post by:
I have an app that was originally 1.1, now migrated to 2.0 and have run into some sporadic viewstate errors...usually saying the viewstate is invalid, eventvalidation failed or mac error. My web...
0
by: Joey Martin | last post by:
This is urgent, so any quick help is much appreciated!!!! I have an ASP page that pulls data from a SQL table and puts it into a basic html table. This is basic stuff. I moved my pages from a...
9
by: Joshua.Buss | last post by:
I am trying to move a record from one linked table to another within access, but I'm a complete beginner to VBA and don't know exactly where to begin. I have an access file that has the two...
3
by: Eric | last post by:
When i run my query it transfer last 4 digits of account number from one table to another and its wrong. There are two tables one i use for parsing. Second thru query i use to move data from temp...
8
by: Lee | last post by:
guys, I have a project need to move more than 100,000 records from one database table to another database table every week. Currently, users input date range from web UI, my store procedure will...
2
by: arial | last post by:
Hi all, I am learning sql server 2000/2005. Now, I need to move data from my one sql server 1 to another sql server 2. I have five tables and data schema is same on both the server. as...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.