Insert into Access from SQL Server

后端 未结 1 1847
执笔经年
执笔经年 2020-12-21 07:57

I\'m looking to copy a few thousand records from SQL Server into Access in C#. The other direction works using SqlBulkCopy. Is there anything in place to do thi

相关标签:
1条回答
  • 2020-12-21 08:43

    This will run against the MS Access OleConnection connection:

    SELECT fld1, fld2 INTO accessTable FROM [sql connection string].sqltable
    

    For example:

    SELECT * INTO newtable 
    FROM 
    [ODBC;Description=Test;DRIVER=SQL Server;SERVER=server\SQLEXPRESS;UID=uid;Trusted_Connection=Yes;DATABASE=Test].table_1
    

    Or to append

    INSERT INTO newtable
    SELECT *
    FROM [ODBC;Description=Test;DRIVER=SQL Server;SERVER=server\SQLEXPRESS;UID=uid;Trusted_Connection=Yes;DATABASE=Test].table_1;
    

    Or with FileDSN

    INSERT INTO newtable
    SELECT * 
    FROM [ODBC;FileDSN=z:\docs\test.dsn].table_1;
    

    You will need to find the right driver to suit, for example

    ODBC;Driver={SQL Server Native Client 11.0};Server=myServerAddress;Database=myDataBase; Uid=myUsername;Pwd=myPassword; 
    

    From http://connectionstrings.com works for me, but check out your client version.

    0 讨论(0)
提交回复
热议问题