简体   繁体   中英

How can I insert a record retrieved from an ms access table into an sql server table?

I have an MS Access database table that I exported to SQL Server 2012 without the data. So now I'd like to copy the data from the access table to the sql table line by line.

    Dim conn As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection(Configuration.ConfigurationManager.ConnectionStrings("ACCESS_DB_DataConnectionString").ToString())
    Dim comm As System.Data.OleDb.OleDbCommand = New System.Data.OleDb.OleDbCommand("Select * FROM " + accessTable)
    Dim rdr As System.Data.OleDb.OleDbDataReader

    Try
        conn.Open()
        rdr = comm.ExecuteReader

        While rdr.Read
             InsertRecord()
        End While
        rdr.Close()
    Catch ex As Exception
        'Error
    Finally
        comm.Dispose()
        conn.Close()
        conn.Dispose()
    End Try
End Sub

Private Sub InsertRecord()
    'What do I do here?  Select into?  But how?
End Sub

I don't want to use a regular insert because I don't care to type out all of the column names. The end goal is to copy what records I can and skip over and obtain the IDs of all the rows that error out.

Thank you

Please take a look at the "SQL Server Import and Export Data" program that comes with SQL Server Management Studio. It does a spectacular job of transferring data to/from SQL Server and a variety of other formats like Access, Excel, OLE, and many others.

SQL Server导入和导出数据

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