插入从SQL Server访问 [英] Insert into Access from SQL Server
问题描述
我期待从SQL Server几千记录复制到在C#中的访问。其他方向的作品使用 SqlBulkCopy的
。是否有适当的反向做这种事?
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 this in reverse?
我想我最好从通过每个记录的每个字段循环,建设令人发指<$ C走就走$ C>插入语句,不仅会采取永远运行,但可能会如果有什么变化可怕的崩溃。
I'm trying my best to stay away from looping through each field in each record and building a heinous Insert
statement that not only would take forever to run, but would likely crash horribly if anything changes.
推荐答案
这将会对运行的MS Access OleConnection连接:
This will run against the MS Access OleConnection connection:
SELECT fld1, fld2 INTO accessTable FROM [sql connection string].sqltable
例如:
SELECT * INTO newtable
FROM
[ODBC;Description=Test;DRIVER=SQL Server;SERVER=server\SQLEXPRESS;UID=uid;Trusted_Connection=Yes;DATABASE=Test].table_1
或者追加
INSERT INTO newtable
SELECT *
FROM [ODBC;Description=Test;DRIVER=SQL Server;SERVER=server\SQLEXPRESS;UID=uid;Trusted_Connection=Yes;DATABASE=Test].table_1;
或用的FileDSN
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;
HTTP ://connectionstrings.com 对我的作品,但检查出你的客户端版本。
From http://connectionstrings.com works for me, but check out your client version.
这篇关于插入从SQL Server访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!