Visual Basic 2012通过登录调用Crystal Reports

时间:2014-10-15 09:59:44

标签: oracle visual-studio-2012 login crystal-reports

我刚刚开始使用Visual Studio 2012,从未接受任何培训,所以原谅我这是一个简单/愚蠢的问题。

我创建了一个相对简单的程序,用户可以使用它来运行Crystal Reports。他们可以选择他们的部门,并获得包含可能报告的列表。如果他们点击按钮"选择",将打开第二个表单,其中包含Crystal Report。

然而,当这出现时,它要求数据库登录。我在主屏幕上创建了3个变量,保存了数据库名称,用户名和密码,并希望在打开报表时使用它。

该报告基于Oracle数据库

包含Crystal文件的表单中包含CrystalReportViewer。在这里,我选择了我的报告。

我在网上找到的代码还没有工作,它仍在询问登录详情:

Imports CrystalDecisions.Shared
Imports CrystalDecisions.CrystalReports.Engine

 Public Class F_QTS_Al4All

Private Sub configureCRYSTALREPORT()
    Dim myConnectionInfo As New ConnectionInfo()

    myConnectionInfo.DatabaseName = F_IJ_IE_Internal_Reporting.Login_Database
    myConnectionInfo.UserID = F_IJ_IE_Internal_Reporting.Login_Username
    myConnectionInfo.Password = F_IJ_IE_Internal_Reporting.Login_Password
    setDBLOGONforREPORT(myConnectionInfo)
End Sub

Private Sub setDBLOGONforREPORT(ByVal myconnectioninfo As ConnectionInfo)
    Dim mytableloginfos As New TableLogOnInfos()
    mytableloginfos = CrystalReportViewer1.LogOnInfo
    For Each myTableLogOnInfo As TableLogOnInfo In mytableloginfos
        myTableLogOnInfo.ConnectionInfo = myconnectioninfo
    Next
End Sub

Private Sub CrystalReportViewer1_Load(sender As Object, e As EventArgs) Handles CrystalReportViewer1.Load

End Sub
End Class

所以我一直在玩一下,并且移动了myConnectionInfo部分也复制到了CrystalReportViewer1部分。现在,我得到一个例外,说NullReferenceException是由用户代码

无法处理的

我的想法已经不多了,您是否知道如何更改代码以便它不再需要凭据?

我还在某处读到我可以将报告源保持为空,但如果我将报告留空,我不知道如何调用该报告?

提前多多感谢

亲切的问候

1 个答案:

答案 0 :(得分:0)

我发现了如何做到这一点。我在主屏幕中创建了另一个名为reportpath的共享变量。我填写这个是我决定需要打电话的报告。之后我有以下代码。

Imports CrystalDecisions.Shared
Imports CrystalDecisions.CrystalReports.Engine

Public Class F_Report

Private Sub configureCRYSTALREPORT()
    Dim myConnectionInfo As New ConnectionInfo()

    myConnectionInfo.DatabaseName = F_IJ_IE_Internal_Reporting.Login_Database
    myConnectionInfo.UserID = F_IJ_IE_Internal_Reporting.Login_Username
    myConnectionInfo.Password = F_IJ_IE_Internal_Reporting.Login_Password
    setDBLOGONforREPORT(myConnectionInfo)
End Sub

Private Sub setDBLOGONforREPORT(ByVal myconnectioninfo As ConnectionInfo)
    Dim mytableloginfos As New TableLogOnInfos()
    mytableloginfos = CrystalReportViewer1.LogOnInfo
    For Each myTableLogOnInfo As TableLogOnInfo In mytableloginfos
        myTableLogOnInfo.ConnectionInfo = myconnectioninfo
    Next
End Sub

Private Sub CrystalReportViewer1_Load(sender As Object, e As EventArgs) Handles CrystalReportViewer1.Load
    CrystalReportViewer1.ReportSource = F_IJ_IE_Internal_Reporting.ReportPath
    Dim myConnectionInfo As New ConnectionInfo()

    myConnectionInfo.DatabaseName = F_IJ_IE_Internal_Reporting.Login_Database
    myConnectionInfo.UserID = F_IJ_IE_Internal_Reporting.Login_Username
    myConnectionInfo.Password = F_IJ_IE_Internal_Reporting.Login_Password
    setDBLOGONforREPORT(myConnectionInfo)
End Sub
End Class