Crystal Reports使用VB.net在Database Expert中设置数据库路径 [英] Crystal report Database path setting in Database Expert using VB.net

查看:68
本文介绍了Crystal Reports使用VB.net在Database Expert中设置数据库路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我在Vb.net创建了我的应用程序,并使用了水晶报告。现在,晶体报告正在访问MS-Access数据库以生成报告。如何在数据库专家中为其提供动态路径,例如应用程序的安装路径?在开发应用程序时,它与位于我系统驱动器中的数据库连接,但如果我想在客户端系统中安装它,我将如何操作?如何在多用户系统的情况下实现相同的功能?

解决方案

我找到了一个解决方案,这很简单。只需添加连接信息并应用它。现在,每当报告加载时,它将应用提供的连接信息。



 私人  Sub  frmreportviewer_Load( ByVal  sender  As 系统。对象 ByVal  e 作为 System.EventArgs)句柄  MyBase  .Load 
Dim CrTables As
Dim crtableLogoninfo 作为 TableLogOnInfo
Dim crConnectionInfo 作为 ConnectionInfo
尝试
' reportdoc object
Dim cryRpt As New ReportDocument

加载报告
cryRpt.Load(My.Application.Info.DirectoryPath.ToString()& \ Report.1rpt

' 参数定义(如果有的话)

' 提供连接信息。这很重要,您可以根据数据库位置进行更改
使用 crConnectionInfo
.ServerName = My.Application.Info。 DirectoryPath.ToString()& \abc.mdb
' 。DatabaseName =
' .UserID =
。密码= 密码
结束 使用

CrTables = cryRpt.Database.Tables
对于 每个 CrTable CrTables
crtableLogoninfo = CrTable.LogOnInfo
crtableLogoninfo.ConnectionInfo = crConnectionInfo
CrTable.ApplyLogOnInfo(crtableLogoninfo)
Next

CrystalReportViewer1.Repor tSource = cryRpt
CrystalReportViewer1.Refresh()
Catch ex As Exception
MsgBox(ex.Message)
结束 尝试
结束 Sub


如果您正在使用Ms-访问然后只需按照下面提到的代码块,将您的访问数据库正常连接到水晶报告。



============== ========== X ========================

导入CrystalDecisions.CrystalReports.Engine

进口CrystalDecisions.Shared



公共舱Form4



私人子Form4_Load( ByVal sender As System.Object,ByVal e As System.EventArgs)处理MyBase.Load

尝试

Dim S作为新账单

With S <无线电通信/>
.FileName =cryReport.RPT

.SetDatabaseLogon(Admin,PASSWORD)

结束



CrystalReportViewer1.ReportSource = S

CrystalReportViewer1.Refresh()

Catch ex As Exception

MsgBox(ex 。消息)

结束尝试

结束子



结束班

= ======================= X ========================

Hi,

I have created my application in Vb.net and have used crystal report. Now the crystal report is accessing a MS-Access database to generate report. How can I provide it a dynamic path such as application's installation path in database expert ? While developing the application it connects with the database which is located in a drive of my system, but if I want to install it in client system how I will do it? How to implement the same in case of multi-user system ?

解决方案

I found a solution and it's very simple to do. Just add connection info and apply it. Now every time when reports loads it will apply the connection info provided.

Private Sub frmreportviewer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim CrTables As Tables
        Dim crtableLogoninfo As New TableLogOnInfo
        Dim crConnectionInfo As New ConnectionInfo
        Try
			'reportdoc object
            Dim cryRpt As New ReportDocument
			
            'load report
            cryRpt.Load(My.Application.Info.DirectoryPath.ToString() & "\Report1.rpt")
            
			'parameters definition(if any)
            
			'provide connection info. This is important and you can change it as per your db location
			With crConnectionInfo
                .ServerName = My.Application.Info.DirectoryPath.ToString() & "\abc.mdb"
                '.DatabaseName = ""
                '.UserID = ""
                .Password = "password"
            End With

            CrTables = cryRpt.Database.Tables
            For Each CrTable In CrTables
                crtableLogoninfo = CrTable.LogOnInfo
                crtableLogoninfo.ConnectionInfo = crConnectionInfo
                CrTable.ApplyLogOnInfo(crtableLogoninfo)
            Next

            CrystalReportViewer1.ReportSource = cryRpt
            CrystalReportViewer1.Refresh()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub


If you are using Ms-Access then simply follow the code block mentioned below and connect your access database normally to the crystal report.

========================X========================
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared

Public Class Form4

Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
Dim S As New Bills
With S
.FileName = "cryReport.RPT"
.SetDatabaseLogon("Admin", "PASSWORD")
End With

CrystalReportViewer1.ReportSource = S
CrystalReportViewer1.Refresh()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

End Class
========================X========================


这篇关于Crystal Reports使用VB.net在Database Expert中设置数据库路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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