Results 1 to 8 of 8

Thread: getting data from one database to another database

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2003
    Location
    New Hampshire, USA
    Posts
    15

    getting data from one database to another database

    I'm attempting to learn VB.Net on my own and I have a question. I want to get data from one access database to another. I actually did it by populating invisible text boxes on my form first and then sending it to the other database, but I'm wondering if theres a way to do it directly. Any help would be great. Thanks.

  2. #2
    Fanatic Member ahara's Avatar
    Join Date
    Nov 2003
    Location
    Toronto
    Posts
    531
    well...one way that's a bit more direct would be to first fetch some records into a recordset from the first db table, then loop through the record set and use command object to perform inserts. (more efficient than your text box idea), although if there are a lot of records involved, (over 100,000) and numerous tables, you could be at this for a while. What about using Access's import features? I am not an expert with Access, but in the past I have imported data successfully from Excel - I see no reason why you could not do it with another mdb file (assuming this is a one time process for purposes unknown to me)

    cheers
    "Knowledge is gained when different people look at the same information in different ways"

    - Louis Pasteur

  3. #3
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951
    You could use a SQL such as "Insert into destinationtablename Select * from sourcetablename"

  4. #4
    Fanatic Member ahara's Avatar
    Join Date
    Nov 2003
    Location
    Toronto
    Posts
    531
    Originally posted by Pasvorto
    You could use a SQL such as "Insert into destinationtablename Select * from sourcetablename"
    but how do you do that when the tables are in separate DB's?
    "Knowledge is gained when different people look at the same information in different ways"

    - Louis Pasteur

  5. #5
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951
    You got me on that one. The simplest way, I think would be:

    Open input recordset
    open output recordset

    input.movefirst
    do
    output.addnew
    output![field1] = input![field1]
    .....
    .....
    output![fieldx] = input![fieldx]
    ouput.update
    input.movenext
    loop while not input.eof

    input.close
    output.close

  6. #6
    Fanatic Member ahara's Avatar
    Join Date
    Nov 2003
    Location
    Toronto
    Posts
    531
    yeah...that's what I was thinking....do you think it might be quicker to just use Access gui interface and import? I really don't know.
    "Knowledge is gained when different people look at the same information in different ways"

    - Louis Pasteur

  7. #7
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951
    I've never imported between ACCESS dbs, only ACCESS to SQL Server.

  8. #8
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    You could use a SQL such as "Insert into destinationtablename Select * from sourcetablename"

    but how do you do that when the tables are in separate DB's?
    The syntax of the Insert Into and Select statements allow you to specify a filename.

    For example - I have the Northwind.mdb (Access 97) and NWind.mdb (Access 2000) sample databases on my PC. The following code will create a new table called Suppliers2 in the Northwind database and populate the new table with data from NWind.Suppliers.

    VB Code:
    1. Dim objConn As ADODB.Connection
    2. Dim strSQL As String
    3.  
    4. Set objConn = New ADODB.Connection
    5.  
    6. objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=M:\Testing\NWind.mdb"
    7.  
    8. strSQL = "Select * Into Suppliers2 In 'M:\Testing\northwind.mdb' From Suppliers"
    9.  
    10. objConn.Execute strSQL
    11.  
    12. objConn.Close

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width