本文介绍了ruby和accdb(MS Access)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有基本的Windows XP系统,ruby和ms Access 2007文件(例如c:/foo/bar.accdb)文件,那么读取该.accdb文件的最不麻烦的方法是什么.

If I have a base windows xp system, ruby and an ms access 2007 file (say c:/foo/bar.accdb) file, what's the least intrusive method for reading that .accdb file.

  • xp系统上需要安装什么.
  • 具体的连接字符串是什么.

推荐答案

遵循这些思路可以使您入门.当然,您需要修改某些值,例如;路径,文件名,SQLstatement等.

Something along these lines should get you started. Of course, you'll need to modify some of the values like; path, filename, SQLstatement, etc.

使用Jet引擎的MDB文件(Access 2003格式及更低版本)

MDB file (Access 2003 format and older) using the Jet engine

require 'win32ole'
connection = WIN32OLE.new('ADODB.Connection')
connection.Open('Provider=Microsoft.Jet.OLEDB.4.0;
                 Data Source=c:\path\filename.mdb')

使用ACE引擎的ACCDB文件(Access 2007格式和更高版本)

ACCDB file (Access 2007 format and newer) using the ACE engine

require 'win32ole'
connection = WIN32OLE.new('ADODB.Connection')
connection.Open('Provider=Microsoft.ACE.OLEDB.12.0;
                 Data Source=c:\path\filename.accdb')

要执行不返回数据的SQL查询,请使用:

To execute a SQL query that doesn't return data use:

connection.Execute("INSERT INTO Table VALUES ('Data1', 'Data2');")

执行返回记录集的查询:

To perform a query that returns a recordset:

recordset = WIN32OLE.new('ADODB.Recordset')
recordset.Open(SQLstatement, connection)

这篇关于ruby和accdb(MS Access)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 18:27