前端之家收集整理的这篇文章主要介绍了
在VB.NETxi下调用Access中的Report,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_
403_0@在VB.NET中可以用两种方式
调用Access
数据库:ADO.NET或者
自动化(Automation)。
@H_
403_0@如果你是要操纵Access下的数据那么ADO.NET必然是首选。如果你要操纵Access下的Form,Report就必须使用
自动化。
@H_
403_0@以下是一个示例:
- 新建一个Window Forms Application.
- 引用”Microsoft.Office.Interop.Access” 14.0(因为我的实现环境是MS Access 2010,Visual Studio 2010)
- 数据库情况如下:
- 代码如下:
Imports Access = Microsoft.Office.Interop.Access
Imports MyLog4Net
Public Class Form1
Private mlog As New MyLog4Net.MyLogger(GetType(Form1),"Debug.log")
Private Sub Button1_Click(sender As System.Object,e As System.EventArgs) Handles Button1.Click
Dim OAccess As Access.Application
Dim OFD As New OpenFileDialog
Try
OFD.Multiselect = False
OFD.Filter = "Access File 2010|*.accdb"
OFD.ShowDialog()
OAccess = New Access.Application
OAccess.OpenCurrentDatabase(OFD.FileName,False)
OAccess.Visible = True
OAccess.DoCmd.OpenReport("TestTable1Report",Access.AcView.acViewPreview)
Catch ex As Exception
mlog.ERROR(ex.Message)
End Try
End Sub
End Class