1
votes

I prepare a report with Crystal Reports 8.5.I want to call this report from C#.

This is my stored procedure in the report:

create procedure GetCari
    @cariid int 
as
    select 
        CariIdent, CariKod, CariNam, CariTip, CariTipEx, CariStatu 
    from 
        Cariler 
    where 
        CariIdent = @cariid

My C# code, firstly I taken error parameter is not correct also The Table 'GetCari' could not be found. But I don't use table I'm using a stored procedure:

try
        {

            CrystalReportViewer cw = new CrystalReportViewer();
            cw.Dock = DockStyle.Fill;

            panel1.Controls.Add(cw);

            ReportDocument cryRpt = new ReportDocument();
            TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
            TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
            ConnectionInfo crConnectionInfo = new ConnectionInfo();
            Tables CrTables;





            ParameterField paramField = new ParameterField();
            ParameterFields paramFields = new ParameterFields();
            ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();

            paramField.Name = "@cariid";
            paramDiscreteValue.Value = 1;
            paramField.CurrentValues.Add(paramDiscreteValue);
            paramFields.Add(paramField);

            cw.ParameterFieldInfo = paramFields;



            string path = @"C:\..\Reports\Report2.rpt";



            cryRpt.Load(path);


            ParameterFieldDefinitions crParameterFieldDefinitions;
            ParameterFieldDefinition crParameterFieldDefinition;
            ParameterValues crParameterValues = new ParameterValues();
            ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();

            crParameterDiscreteValue.Value = Convert.ToInt32(1);
            crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
            crParameterFieldDefinition = crParameterFieldDefinitions["@cariid"];
            crParameterValues = crParameterFieldDefinition.CurrentValues;

            crParameterValues.Clear();
            crParameterValues.Add(crParameterDiscreteValue);
            crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);



            crConnectionInfo.ServerName = "server";
            crConnectionInfo.DatabaseName = "db";
            crConnectionInfo.UserID = "sa";
            crConnectionInfo.Password = "1234";

            CrTables = cryRpt.Database.Tables;


            foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
            {
                crtableLogoninfo = CrTable.LogOnInfo;
                crtableLogoninfo.ConnectionInfo = crConnectionInfo;

                CrTable.ApplyLogOnInfo(crtableLogoninfo);


            }
            cryRpt.SetParameterValue("@cariid", 1);

            cryRpt.VerifyDatabase();

            cryRpt.Refresh();

            cw.ReportSource = cryRpt;


            cw.Refresh();


        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }

This code not working. It is giving error the parameter is incorrect. I really don't understand this problem where I m doing wrong

1
This comes down to how you designed the report. You would wire up your proc call in the designer and pass the report parameter.bhmahler
Yes but it is not my search answer.I can call this sp on crystal designer but I have to do programmaticallySezer Erdogan
Right, but you are setting the report parameter value not the proc value when generating the report. What did you call your report parameter? I see you have @cariid but I am guessing the report parameter is not the proc parameter so most likely doesn't start with @, but then again, without seeing your report definitions, I can't tellbhmahler
my report parameter is @cariidSezer Erdogan
If I put without @ it is giving invalid index errorSezer Erdogan

1 Answers

2
votes

I solved my problem.Firstly I changed my application compile platform target to x86(32 bit).After I used CrystalDecisions.CrystalReports.Engine lib version 13.0.2000.0 and now it is working fine.