Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Software > ADO Data > Copying from on...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 5 Topic 4252 of 4320
Post > Topic >>

Copying from one record set to another

by =?Utf-8?B?SU5UUDU2?= <INTP56@[EMAIL PROTECTED] > Jun 18, 2008 at 12:28 PM

Hi, I am trying to do a workaround while I'm trying to resolve an issue
with 
the SQL Server implementation that does the same thing, but is currently 
broken.

Basically, I have an MDB file with two tables in it, and two tables in SQL

Server that look just like the tables in the access database

Both tables have an auto increment field on the Access side. I want to 
select the new records from the Access db and insert them into the SQL DB.

I can get to both DBs from Excel. I can write code that pulls the new 
records  from Access into Excel, now I want to push those records into SQL

Server.

It seems to me I don't really even need the worksheet. If I got a record
set 
from Access, and I know it's the same structure as what's in SQL Server,
is 
there a way to insert the record set from Access in SQL Server?

This doesn't give me any errors ....

Private Sub MoveDataFromAccessToSQLServer()
    Dim ADODB_ACConnection As New ADODB.Connection
    Dim ADODB_SQConnection As New ADODB.Connection
    Dim ADODB_ACRecordSet As New ADODB.Recordset
    Dim ADODB_SQRecordSet As New ADODB.Recordset

    On Error GoTo ExitRoutine

    With ADODB_ACConnection
        .ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data 
Source=<FileName>.mdb;Persist Security Info=False;"
        .Open
        If .State <> adStateOpen Then
            MsgBox "Could not open Access database"
            GoTo ExitRoutine
        End If
    End With
    
    With ADODB_ACRecordSet
        .ActiveConnection = ADODB_ACConnection
        .Open "SELECT * FROM Experiment WHERE autonumber > 1000"
    End With

    With ADODB_SQConnection
        .ConnectionString = "Provider=SQLNCLI.1;Integrated 
Security=SSPI;Persist Security Info=False;Initial Catalog=<DBName>;Data 
Source=<Server>"
        .Open
        If .State <> adStateOpen Then
            MsgBox "Could not open SQL database"
            GoTo ExitRoutine
        End If
    End With

    With ADODB_SQRecordSet
        .ActiveConnection = ADODB_SQConnection
        .Open "SELECT * FROM dbsrc.vExperiment WHERE 1=0" 'This gives me
an 
empty record set
    End With

    'Here is where I am stuck. I want to just insert everything
    'in ADODB_ACRecordSet into ADODB_SQRecordSet
    'Is there a way to do this without iterating thorugh
    'every field in every row?
    
ExitRoutine:
    If Err.Number <> 0 Then
        strError = CStr(Err.Number) & vbCrLf
        strError = strError & Err.Description & vbCrLf
        strError = strError & Err.Source
        MsgBox strError
    End If
    
    
    If ADODB_ACRecordSet.State <> adStateClosed Then
        ADODB_ACRecordSet.Close
    End If
    Set ADODB_ACRecordSet = Nothing

    If ADODB_SQRecordSet.State <> adStateClosed Then
        ADODB_SQRecordSet.Close
    End If
    Set ADODB_SQRecordSet = Nothing
   
    If ADODB_ACConnection.State <> adStateClosed Then
        ADODB_ACConnection.Close
    End If
    Set ADODB_ACConnection = Nothing
    
    If ADODB_SQConnection.State <> adStateClosed Then
        ADODB_SQConnection.Close
    End If
    Set ADODB_SQConnection = Nothing

End Sub
 




 5 Posts in Topic:
Copying from one record set to another
=?Utf-8?B?SU5UUDU2?= <  2008-06-18 12:28:00 
Re: Copying from one record set to another
"Bob Barrows [MVP]&q  2008-06-18 16:02:42 
Re: Copying from one record set to another
=?Utf-8?B?SU5UUDU2?= <  2008-06-18 19:46:01 
Re: Copying from one record set to another
"Bob Barrows [MVP]&q  2008-06-19 06:13:46 
Re: Copying from one record set to another
"Bob Barrows [MVP]&q  2008-06-19 09:17:29 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Nov 22 14:47:24 CST 2008.