如何使用VB.net访问Access 2010中的数据 [英] How do I access data in Access 2010 using VB.net

查看:257
本文介绍了如何使用VB.net访问Access 2010中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试完成这些我曾经能够在VB 6.0和Access 2000中没有问题的5个步骤。我现在尝试在VB Studio 2012和Access 2010中做类似的事情。我可以完成前2个步骤,需要帮助剩余部分。



1.导航并选择数据库

2.选择数据库后,使用表格填充列表框数据库的名称

3.在列表框中选择一个表名后,用数据库中的字段填充其他几个列表框

4.在每个辅助列表框中,选择适当的字段来访问来自

的数据5.根据所选字段中数据的连续顺序并导出到Word文档,遍历数据库,检索适当的记录。



感谢您提供的任何帮助。

解决方案

您指定的大部分内容都只是标准的数据库工作,所以我我会留给你学习,但是我会指出你可能很难找到的部分方向。



我会使用ADO.net,OleDb和ACE引擎。如果您安装了Office,那么您应该已经拥有ACE引擎,如果没有,您可以在此处获取: Microsoft Access数据库引擎2010可再发行组件 [ ^ ]



以下是一些可以帮助您制定连接字符串的信息: http://www.connectionstrings.com/access/ [ ^ ]



一旦连接到数据库,就可以获得架构信息(例如表格列表): br />
http://msdn.microsoft.com/ en-us / library / ms135982(v = vs.110).aspx [ ^ ]







http://msdn.microsoft.com/en -us / library / system.data.oledb.oledbconnection.getoledbschematable(v = vs.110).aspx [ ^ ]

(这个更难以使用并仅适用于OleDb。)





要获取列列表(及其类型),我更喜欢使用DataReader,因为它适用于许多数据提供者。

我创建一个命令,如SELECT * FROM tablename WHERE 0 = 1,调用ExecuteReader,然后访问DataReader的GetSchemaTable方法以获取包含列详细信息的DataTable。

如果您不需要详细信息,可以简单地迭代字段并使用GetName

http://msdn.microsoft.com/en-us/library/ system.data.idatarecord.getname(v = vs.110).aspx [ ^ ]

来构建列名列表。





我还会为我最近的文章添加一个无耻的插件:通过ADO.NET接口简化数据库访问 [ ^ ]


PIEBALDconsult的Solution1非常好!



我想提供另一个有用的链接:

访问Microsoft Off来自.NET应用程序的数据 [ ^ ]

如何从Visual Basic .NET自动化Microsoft Access [ ^ ]

深思熟虑:使用ADO.NET编辑Access数据库 [ ^ ]

从ADO迁移到ADO.NET [ ^ ]



更多信息: CodeProject知识库 [ ^ ]。

I am trying to accomplish these 5 steps which I used to be able to do without problems in VB 6.0 and Access 2000. I am now trying to do similar in VB Studio 2012 and Access 2010. I can accomplish first 2 steps, need help with remainder.

1. Navigate to and select a database
2. Upon selection of database, populate a listbox with the table names of the database
3. Upon selection of a table name in the listbox, populate several other listboxes with the fields in the database
4. In each of the secondary listboxes, select the appropriate field to access data from
5. Iterate through database, retrieving appropriate records, based on sequential order of the data from the selected fields and exporting to a Word document.

Thanks for any help you can give me.

解决方案

Most of what you specify is just standard database work, so I'll leave that to you to learn, but I'll point you in the direction of some parts that may be hard to find.

I'd use ADO.net , OleDb , and the ACE engine. If you have Office installed then you should have the ACE engine already, if not you can get it here: Microsoft Access Database Engine 2010 Redistributable [^]

Here's some information that should help you formulate a connection string: http://www.connectionstrings.com/access/[^]

Once you have a Connection to the database, you can get schema information (e.g. a list of tables) with:
http://msdn.microsoft.com/en-us/library/ms135982(v=vs.110).aspx[^]

or

http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbconnection.getoledbschematable(v=vs.110).aspx[^]
(This one is harder to use and is only for OleDb.)


To get the list of columns (and their types) I prefer to use a DataReader because it works with many data providers.
I create a command like "SELECT * FROM tablename WHERE 0=1", call ExecuteReader, and then access the DataReader's GetSchemaTable method to get a DataTable with the column details.
If you don't need the details, you can simply iterate the fields and use GetName
http://msdn.microsoft.com/en-us/library/system.data.idatarecord.getname(v=vs.110).aspx[^]
to build the list of column names.


I'll also include a shameless plug for my most recent article: Simplified Database Access via ADO.NET Interfaces[^]


Solution1 by PIEBALDconsult is very good!

I'd like to provide another useful links:
Accessing Microsoft Office Data from .NET Applications[^]
How To Automate Microsoft Access From Visual Basic .NET[^]
Walkthrough: Editing an Access Database with ADO.NET[^]
Migrating from ADO to ADO.NET[^]

More on: CodeProject Knowledge Base[^].


这篇关于如何使用VB.net访问Access 2010中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆