0

我正在使用 Visual Studio 在 VB.net 中创建一个程序,并且某些表单使用 Crystal Reports 来显示 PDF 报告,但我遇到了数据库连接问题。VB.net 代码可以毫无问题地访问数据库,但是当表单显示报告时,它会要求我输入用户名和密码,如果我编写它们,则无法连接。应用程序和报表共享同一个数据库,我使用相同的数据进行连接,但 Crystal Reports 失败。你能帮助我吗?

4

3 回答 3

1

这是我拥有的一个片段(在 C# 中,但应该让您了解我是如何做到的):

    CrystalReportSource CrystalReportSource1 = new CrystalReportSource();
    CrystalReportViewer CrystalReportViewer1 = new CrystalReportViewer();

    CrystalReportViewer1.ReportSource = CrystalReportSource1;
    CrystalReportViewer1.EnableParameterPrompt = false;
    CrystalReportSource1.Report.FileName = "Report3.rpt";
    CrystalReportSource1.EnableCaching = false;

    CrystalReportSource1.ReportDocument.SetParameterValue(0, ponumber);
    CrystalReportSource1.ReportDocument.SetParameterValue(1, receiptno);



    TableLogOnInfo logOnInfo = new TableLogOnInfo();

    logOnInfo.ConnectionInfo.ServerName = ConfigurationManager.AppSettings["WarehouseReportServerName"];
    logOnInfo.ConnectionInfo.DatabaseName = ConfigurationManager.AppSettings["WarehouseReportDatabaseName"];
    logOnInfo.ConnectionInfo.UserID = ConfigurationManager.AppSettings["WarehouseReportUserID"];
    logOnInfo.ConnectionInfo.Password = ConfigurationManager.AppSettings["WarehouseReportPassword"];

    TableLogOnInfos infos = new TableLogOnInfos();
    infos.Add(logOnInfo);
    CrystalReportViewer1.LogOnInfo = infos;

    maindiv.Controls.Add(CrystalReportSource1);
    maindiv.Controls.Add(CrystalReportViewer1);


    CrystalReportViewer1.DataBind();
于 2012-12-19T21:43:54.493 回答
0

尽管您说您正在使用设计器,但我会发布一些对我有用的代码,也许它会对您有所帮助:

       Dim cryRpt As New ReportDocument
       Dim strReportPath As String = 'The Path of the rpt file
       cryRpt.Load(strReportPath)
       cryRpt.SetDataSource(Me.crData) 'crData is a datatable with data for the report

       crvReport.ReportSource = cryRpt 'crvReport is the CrystalReportViewer in my form
于 2012-12-19T14:46:50.977 回答
0

在“SetDataSource”中设置时检查数据中是否存在所有字段

于 2017-02-14T19:51:38.160 回答