开发者

Crystal report With parameter passing & change database information dynamically

Please help me out Crystal report With more than one parameters passing & change database information dynamically. I had code which is as follows:

        ParameterFields paramFields = new ParameterFields();
        ReportDocument reportDocument = new ReportDocument();
        reportDocument.Load(Server.MapPath(ReportName + ".rpt"));


        ParameterDiscreteValue crParameterDiscreteValue= new ParameterDiscreteValue();
        ParameterFieldDefinitions crParameterFieldDefinitions ;
        ParameterFieldDefinition 开发者_运维知识库crParameterFieldLocation ;
        ParameterValues crParameterValues = new ParameterValues();
        crParameterFieldDefinitions= reportDocument.DataDefinition.ParameterFields;

        // 1stParameter Satrt
        crParameterFieldLocation= crParameterFieldDefinitions["@userid"];
        crParameterValues= crParameterFieldLocation.CurrentValues;
        crParameterDiscreteValue= new CrystalDecisions.Shared.ParameterDiscreteValue();
        crParameterDiscreteValue.Value=Convert.ToInt64(ViewState["userid"]);
        crParameterValues.Add(crParameterDiscreteValue);
        crParameterFieldLocation.ApplyCurrentValues(crParameterValues);
        //1st Parameter End
         // 2nd Parameter Satrt
        crParameterFieldLocation= crParameterFieldDefinitions["@Reportname"];
        crParameterValues= crParameterFieldLocation.CurrentValues;
        crParameterDiscreteValue= new CrystalDecisions.Shared.ParameterDiscreteValue();
        crParameterDiscreteValue.Value=ReportName;
        crParameterValues.Add(crParameterDiscreteValue);
        crParameterFieldLocation.ApplyCurrentValues(crParameterValues);
        //2nd Parameter End
         // 3rd Parameter Satrt
        crParameterFieldLocation= crParameterFieldDefinitions["@SessionId"];
        crParameterValues= crParameterFieldLocation.CurrentValues;
        crParameterDiscreteValue= new CrystalDecisions.Shared.ParameterDiscreteValue();
        crParameterDiscreteValue.Value=Session.SessionID.ToString();
        crParameterValues.Add(crParameterDiscreteValue);
        crParameterFieldLocation.ApplyCurrentValues(crParameterValues);
        //3rd Parameter End

        CrystalReportViewer1.ReportSource = reportDocument;
         CrystalReportViewer1.EnableDatabaseLogonPrompt = false;
         ConnectionInfo connectionInfo = new ConnectionInfo();
         connectionInfo.ServerName = "192.168.0.245";
         connectionInfo.DatabaseName = "Databasename";
         connectionInfo.UserID = "sa";
         connectionInfo.Password = "Password1";
        TableLogOnInfo tableLogOnInfo = new TableLogOnInfo();
        tableLogOnInfo.ConnectionInfo= connectionInfo;

        foreach (CrystalDecisions.CrystalReports.Engine.Table table in reportDocument.Database.Tables)
    {
        table.ApplyLogOnInfo(tableLogOnInfo);
    }

It is now saying "Failed to open a rowset.". When I run the store procedure manually with the exact parameter values it showing the results. So the store procedure is returning the values. Please help me out. During the design of the Crystal report the database server information is different with the passing one.


Rather than giving the IP in server name, create a DSN in server system(if the database is own with the system, create a DSN in same system) and give the DSN name as server name, and provide appropriate database details to the DSN.

It will work, i implemented and tested.


Create a DSN in your system, then try this code,

ConnectionInfo connectionInfo1 = new ConnectionInfo();
connectionInfo1.ServerName = "Your system dsn name";
connectionInfo1.DatabaseName = "database name";
connectionInfo1.UserID = "username";
connectionInfo1.Password = "secure password";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜