如何从 vb.net 代码将参数传递给水晶报表 [英] How to pass parameters to crystal report from vb.net code

查看:14
本文介绍了如何从 vb.net 代码将参数传递给水晶报表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个水晶报表(交叉表).我没有使用任何数据集,而是使用水晶报表中的向导从我的数据库模式中调用一个过程(提供的提供者是 Microsoft OLEDB 提供者,之后我提供了我的数据库凭据(即架构、用户名、密码)并选择了程序并选择了我想在报告中显示的列).

I have created a crystal report (cross tab). I'm not using any dataset, instead I used the wizard in crystal report to call an procedure from my Database schema (Provider given is Microsoft OLEDB provider for oracle, after which I gave my DB credentials(i.e. schema, username, password) and selected the procedure and selected the columns I wanted to display in the report).

我需要从前端传递 5 个参数来生成报告.在查看水晶报表预览时,通过提供参数,报表可以正常工作.

There are 5 parameters that I need to pass it from the front end to generate the report. While viewing the crystal report preview, by giving parameters, the report works fine.

现在我想从前端(vb.net)传递这 5 个参数以在 CrystalReportViewer 中显示报告.请建议在 aspx.vb 文件中编写的代码.(PS:- 我确实浏览了其他论坛并找到了一些代码,但他们都给出了一些或其他错误,所以我发布一个以便我可以获得特定于我要求的代码.

Now i want to pass these 5 parameters from the front end(vb.net) to show the report in the CrystalReportViewer. Please suggest the code to write in aspx.vb file. (PS:- I did go through other forums and found out some code, but all of them were giving some or the other error, so am posting one so that i can get the code specific to my requirement).

提前谢谢..

推荐答案

我已经得到报告工作...我写了下面的代码:

I have gotten the report to work... I wrote the code below:

    Dim RptDocument As New ReportDocument

    RptDocument.Load(Server.MapPath("rptReport.rpt"))

    RptDocument.SetParameterValue("param1", Session("param1"))
    RptDocument.SetParameterValue("param2", ddlparam2.SelectedValue)
    RptDocument.SetParameterValue("param3", param3.text)
    RptDocument.SetParameterValue("param4", param4.text)
    RptDocument.SetParameterValue("param5", param5.text)

    'Set login info
    Dim myLogin As CrystalDecisions.Shared.TableLogOnInfo

    Dim myTable As Table
    For Each myTable In RptDocument.Database.Tables
        myLogin = myTable.LogOnInfo
        myLogin.ConnectionInfo.ServerName = "server name"
        myLogin.ConnectionInfo.DatabaseName = ""
        myLogin.ConnectionInfo.UserID = "userid"
        myLogin.ConnectionInfo.Password = "pwd"
        myTable.ApplyLogOnInfo(myLogin)
        myTable.Location = myTable.Location

    CrystalReportViewer1.ReportSource = RptDocument

创建了一个系统DNS,必须添加Oracle.DataAccess.dll引用和一个类文件(功能与connectooracle.vb类文件中的相同,但名称不同),也设置global.asax 中的一个连接来引用该类连接并使用Imports Oracle.DataAccess.Client 而不是 Imports System.Data.OracleClient(以避免歧义)...

Created a System DNS and had to add Oracle.DataAccess.dll to reference and a class file (with functions same as that in connectooracle.vb class file but with different name), also set up a connection in global.asax to refer to that class connection and using Imports Oracle.DataAccess.Client instead of Imports System.Data.OracleClient (to avoid ambiguity)...

这以某种方式使它起作用,并且可能有其他解决方案..:)

This somehow made it work and there might be some other solution for that..:)

(For ref:- Adding  myLogin.ConnectionInfo.IntegratedSecurity = True  gave me this error--
Logon failed. Error in File C:DOCUME~1UsernameLOCALS~1TempReport {1AG3DD86-141D-43YA-B6A2-AEDF3459AE49}.rpt: Unable to connect: incorrect log on parameters.)

这篇关于如何从 vb.net 代码将参数传递给水晶报表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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