Copying SQL Server query results into an Access 2010 table

ぃ、小莉子 提交于 2019-12-13 02:56:08

问题


Monthly, I need to get "new" data from our SQL Server business application into an Access 2010 database that contains all our "Management Reports". The Access database has a "staging table" that is to contain the raw data on which the reports are based.

I have no Access experience, but I suggested that we:

  1. Write a query (stored proc?) on our SQL Server that returns the required raw data (...this bit was easy.)
  2. At the end of each month, call the SQL Server stored proc from within Access 2010 (...click a button?)
  3. Save the results of the stored proc into the staging table within Access.

But I'm finding it harder than I expected. I think I can get something ugly working using ADODB in a code-behind, looping through rows in a recordset one by one, and then setting column values one by one. But there must be a better way :)

  • How should I go about getting SQL Server data from Access 2010? (ADODB? DAO? QueryDesigner? other?)

  • Is there a "Insert Recordset Into Table" (or similar) mechanism that I can leverage?


回答1:


Link the relevant sql server table or view to MS Access. Run a query against the linked table using MS Access syntax and update the staging table.

It is also possible to update an MS Access table using a connection string for SQL Server in-line in your query.

SELECT *
INTO   newtable
FROM   [odbc;filedsn=Z:\DSN\test.dsn].table1

Working from the SQL Server end, you can use MS Access as a linked server or run a query and update from there.

INSERT INTO
OPENDATASOURCE(
   'Microsoft.ACE.OLEDB.12.0', 'Data Source=z:\docs\test.accdb')...[table1] 
   ( atext )
SELECT atext FROM table1 WHERE id=2


来源:https://stackoverflow.com/questions/12366590/copying-sql-server-query-results-into-an-access-2010-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!