简体   繁体   中英

How to Import Data from Ms access table to sql server table

I have one table, Checkinout in Ms Access, and I want to import all the data of that table to my SQL Server database Checkinout table, using VB 6.0:

This is my code. It is not working perfectly [is this irony?]

   For i = 1 To LstLog.ListItems.Count
       For j = 1 To LstLog.ColumnHeaders.Count - 1
           REC.Open "insert into xyz (EmpID, LogID,CheckTime,SensorID) Values ('" & _
               LstLog.ListItems(i).SubItems(j) & "','" & _
               LstLog.ListItems(i).SubItems(j) & "','" & _
               LstLog.ListItems(i).SubItems(j) & "','" & _
               LstLog.ListItems(i).SubItems(j) & "' )", CN, _
               adOpenStatic, adLockBatchOptimistic
       Next j
   Next i

You can use DBConvert for this purpose.

DBConvert for Access and MySQL migration tool converts Microsoft Access to MySQL server and MySQL to Access.

You can refer this direct link for referance:

http://dbconvert.com/convert-access-to-mysql-pro.php?DB=1

If you want to do it programatically,

Step By Step Approach:

http://en.kioskea.net/faq/7342-export-access-database-to-mysql

You have used the same sub item id. Drop the inner for loop, eg:

For i = 1 To LstLog.ListItems.Count
    REC.Open "insert into xyz (EmpID, LogID,CheckTime,SensorID) Values ('" & _
        LstLog.ListItems(i).SubItems(1) & "','" & _
        LstLog.ListItems(i).SubItems(2) & "','" & _
        LstLog.ListItems(i).SubItems(3) & "','" & _
        LstLog.ListItems(i).SubItems(4) & "' )", CN, _
        adOpenStatic, adLockBatchOptimistic
Next i

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM