无法从数据库中检索数据

时间:2016-01-27 17:29:57

标签: c# stored-procedures crystal-reports runtime-error runtimeexception

我正在尝试使用Crystal Reports,并将其连接到存储过程,该存储过程带有两个参数。

用户填写两个文本框,我正在尝试将这些参数传递给我的存储过程。

但是我收到了这个错误

  

无法从数据库中检索数据

这是我的代码

private void button1_Click(object sender, EventArgs e)
{
        if (Check(txtFrmDt, txtTDt))
        {
            CryRpt = new ReportDocument();
            CrtableLogonInfos = new TableLogOnInfos();
            CrtableLogonInfo = new TableLogOnInfo();
            CrConnectionInfo = new ConnectionInfo();

            CryRpt.Load("E:\\Users\\Mostafa\\documents\\visual studio 2013\\Projects\\Sales and Inventory System\\Sales and Inventory System\\Inventory_Report.rpt");

            ParameterFields = new CrystalDecisions.Shared.ParameterFields();
            ParameterField = new ParameterField();
            ParameterValue = new ParameterDiscreteValue();

            ParameterField.Name = "@Param1";
            ParameterValue.Value = txtFrmDt.Text;
            ParameterField.CurrentValues.Add(ParameterValue);
            ParameterFields.Add(ParameterField);
            CryRpt.SetParameterValue("@Param1", ParameterValue);

            ParameterField.Name = "@Param2";
            ParameterValue.Value = txtTDt.Text;
            ParameterField.CurrentValues.Add(ParameterValue);
            ParameterFields.Add(ParameterField);
            CryRpt.SetParameterValue("@Param2", ParameterValue);

            CrConnectionInfo.ServerName = "mostafa-pc";
            CrConnectionInfo.DatabaseName = "sales and inventory system";
            CrConnectionInfo.UserID = "sa";
            CrConnectionInfo.Password = "1";

            CrTables = cryRpt.Database.Tables;

            foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
            {
                CrtableLogonInfo = CrTable.LogOnInfo;
                CrtableLogonInfo.ConnectionInfo = CrConnectionInfo;
                CrTable.ApplyLogOnInfo(CrtableLogonInfo);
            }

            crystalReportViewer1.ReportSource = CryRpt;
            crystalReportViewer1.Refresh();
        }
}

我该怎么办?

0 个答案:

没有答案