在将Crystal Report与MS Access数据库一起使用时需要帮助 [英] Need Help in Using Crystal Report with MS Access Database
问题描述
大家好,
我目前正在为组织进行财务申请.我的问题是在我的数据库具有密码时,在运行时使用Crystal报表访问存储在数据库中的数据.这并不是说我根本无法访问存储在一个表中的数据,而是当涉及到两个或多个表时,它总是会产生错误.以下是有效的代码段以及引起问题的代码段:
这很完美:
下面的声明在公共模块中.bas
Hello everyone,
I''m currently working on a financial application for an organization. My problem is accessing data stored in the database using the crystal report at runtime when my database has a password. It is not that I can''t access data stored in a table at all, but when two or more tables are involved, it always generate error. Below are code segments that worked and the ones that give problems:
This one works perfectly:
Declaration below is in public module.bas
Public gbstrDBConnection As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\FinManagerDB.mdb;Persist Security Info=True;Jet OLEDB:Database Password=dontworry"
以下子例程的格式为:
This following sub-routine is in a form:
Private Sub GenerateReport()
Dim mstrUserID As String
Dim DB_Path As String = My.Application.Info.DirectoryPath
Dim con As New OleDbConnection(gbstrDBConnection)
Dim rpt As New crptStationList
Dim com As New OleDbCommand("SELECT * FROM Stations")
mstrUserID = " "
Try
com.CommandType = CommandType.Text ''Command type
com.Connection = con ''give connection to command
Dim adp As New OleDbDataAdapter ''declare adapter
adp.SelectCommand = com ''select command for adapter to worker
Dim ds As New DataSet ''declare dataset
adp.Fill(ds, "Stations") ''fill the dataset through adapter
Try
''Change database path
rpt.SetDataSource(ds)
Catch ex As CrystalDecisions.ReportSource.EnterpriseLogonException
MsgBox(ex.Message)
End Try
CrystalReportViewer1.ReportSource = rpt
CrystalReportViewer1.RefreshReport()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error Alert!")
Finally
End Try
End Sub
在上面,我成功访问了"Stations"表中的数据.
下面的代码段无效
In the above, I successfully access the data in "Stations" table.
The code segment below didn''t work
Private Sub GenerateReport()
Dim DB_Path As String = My.Application.Info.DirectoryPath
Dim con As New OleDbConnection(gbstrDBConnection)
Dim rpt As New crptLoanSummary
Dim com As New OleDbCommand("SELECT * FROM MembersAccount INNER JOIN MemberRegister ON MembersAccount.MemberNo=MemberRegister.MemberNo ORDER BY MembersAccount.MemberNo")
Try
com.CommandType = CommandType.Text ''Command type
com.Connection = con ''give connection to command
Dim adp As New OleDbDataAdapter ''declare adapter
adp.SelectCommand = com ''select command for adapter to worker
Dim ds As New DataSet ''declare dataset
adp.Fill(ds, "MembersAccount,MemberRegister") ''fill the dataset through adapter
Try
''Change database path
rpt.SetDataSource(ds)
Catch ex As CrystalDecisions.ReportSource.EnterpriseLogonException
MsgBox(ex.Message)
End Try
CrystalReportViewer1.ReportSource = rpt
''
CrystalReportViewer1.RefreshReport()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error Alert!")
Finally
End Try
End Sub
在上面,我尝试从两个表(即"MembersAccount"和"MemberRegister")中提取数据,但没有成功.
上面通常会弹出一个数据库登录"对话框,要求输入连接字符串中已包含的database:,LoginID:和Password:.
如果你们能为我纾困,我将感到非常高兴.
In the above, I tried to extract data from two tables i.e. "MembersAccount" and "MemberRegister" without success.
The above, usually pop up a "Database Login" dialog box requesting for database:, LoginID:, and Password:, which had already been included in the connection string.
I will be very glad if you guys can bail me out.
Thanks
推荐答案
不要继续创建新的连接.创建单个实例并将其传递.
Don''t keep creating new connections. Create a single instance and pass it around.
按我个人,您必须先集中数据库.
然后使用数据集从表中获取字段.
试试这个.
As Per me You must Centralize your Database First.
And then Use DataSets to Fetch The Fields From Your Table.
Try This.
这篇关于在将Crystal Report与MS Access数据库一起使用时需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!