CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: ACCESS TO SQL

  1. #1
    Join Date
    Sep 1999
    Posts
    92

    ACCESS TO SQL

    Hi all,

    Is there a simple method to read an access 97 mdb file an insert all the record into SQL database from VB?

    Thank a lot guys


  2. #2
    Join Date
    Feb 2001
    Location
    Stamford CT USA
    Posts
    2,167

    Re: ACCESS TO SQL

    Use ADO to read from Access97 and then dump it into SQL.

    Sub TransferData(oDBSrc as ADODB.Connection, oDBNew as ADODB.Connection, szTableName as string)
    ' note, this proc assumes the conenction to both DBs have been made and passed in via the first
    ' 2 parameters. It also assumes that TABLE pointed by szTableName exist on both DB and has the
    ' same structure
    dim oRSSrc as new ADODB.Recordset
    dim oRSNew as new ADODB.Recordset

    ' open table on both db
    call oRSSrc.Open(szTableName, oDBSrc)
    call oRSNew.Open(szTableName, oDBNew)

    ' loop through the old table
    while not oRSSrc.EOF
    With oRSNew
    .AddNew
    .Fields(0).Value = oRSSrc.Fields(0).Value
    .Fields(1).Value = oRSSrc.Fields(1).Value
    .Fields(2).Value = oRSSrc.Fields(2).Value
    .Update
    End With
    wend

    ' close recordsets
    if (oRSSrc.State <> adStateClosed) then oRSSrc.Close
    if (oRSNew.State <> adStateClosed) then oRSNew.Close
    End Sub




    -Cool Bizs

    Good Luck,
    -Cool Bizs

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

Featured