无法在CrystalReports中生成ondemand subReport [英] Cannot generate ondemand subReport in CrystalReports

查看:82
本文介绍了无法在CrystalReports中生成ondemand subReport的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想针对MainReport中特定字段的每一行生成 ondemand SubReport ,即单击每个ondemand SubReport链接将以相同的形式生成相应的数据行(但是新的报告文档)



MainReport n SubReport的数据通过get_receivedData Storedprocs使用 refcursors 从两个不同包下的数据库中的两个不同表调用。我写了n成功编译了Storedprocs(除了参数名称之外都是相似的)。我还可以在我的Webform1.aspx中成功查看MainReport中的数据。但是,在单击任何子报表ondemand链接时,会发生错误/异常。起初出现错误登录失败。文件CrystalReport_More错误{E5618E1D-3141-47D1-9058-8D7CF11B6AE2} .rpt:无法连接到数据库:登录参数错误



当我在subReport方法中设置断点时



i want to generate an ondemand SubReport against each row of a particular field in the MainReport i.e. clicking each ondemand SubReport link will generate a corresponding row of data in the same form(but new report document)

The data for the MainReport n SubReport are called via get_receivedData Storedprocs using refcursors, from two different tables in the database under two different packages. I've written n compiled the Storedprocs successfully(both similar except parameternames). I can also view The data in the MainReport succesfully in my Webform1.aspx. But while clicking on any of the subreport ondemand links errors/exceptions occur occur. At first there was an error "Logon failed. Error in File CrystalReport_More {E5618E1D-3141-47D1-9058-8D7CF11B6AE2}.rpt:Unable to connect to database: Incorrect logon Parameters error"

When i set breakpoints in my subReport method

public DataTable getSubOrders(int id)
        {
            try
            {
                if (Con.State != ConnectionState.Open)
                {
                    Con.Open();
                }
                ReportDocument subreport = new ReportDocument();
                //Stored procedure calling. It is already in sample db.     
                cmd.Parameters.Clear();
                cmd.CommandText = "pkg_test_MORE.sp_get_received_data_MORE";
                cmd.CommandType = CommandType.StoredProcedure;
                OracleParameter Para_ID = new OracleParameter("Temp_id", OracleDbType.Int32);
                OracleParameter Para_RSCUR = new OracleParameter("nreturned", OracleDbType.RefCursor);
                Para_ID.Direction = ParameterDirection.Input;
                Para_ID.Value = id;
                Para_RSCUR.Direction = ParameterDirection.Output;
                cmd.Parameters.Add(Para_ID);
                cmd.Parameters.Add(Para_RSCUR);

                OracleDataAdapter adapter = new OracleDataAdapter(cmd);
                //OracleDataReader dr = null;

                string MORE_DETAILS = ds.Tables[0].TableName;

            adapter.Fill(ds, "MORE_DETAILS");
                DataRow moreDetailsRow;

foreach (DataRow row in ds10.Tables["MORE_DETAILS"].Rows)
                {
                    moreDetailsRow = ds10.Tables["MORE_DETAILS"].NewRow();
                    moreDetailsRow["RNK"] = Convert.ToInt32(row["RNK"].ToString());
                    moreDetailsRow["TITLE"] = row["TITLE"].ToString();
                    moreDetailsRow["CAST1"] = row["CAST1"].ToString();
                    moreDetailsRow["RATED"] = Convert.ToInt32(row["RATED"].ToString());
                    moreDetailsRow["PROFIT"] = Convert.ToInt32(row["PROFIT"].ToString());
                    ds10.Tables["MORE_DETAILS"].Rows.Add(moreDetailsRow);
                }



                ds.Tables["MORE_DETAILS"].AcceptChanges();
                subreport.Load(HttpContext.Current.Server.MapPath("~/Reports/CrystalReport3.rpt"));


                subreport.SetDataSource(ds10.Tables["MORE_DETAILS"]);
                // Preview the subreport.
                CrystalReportViewer3.ReportSource = subreport;
                CrystalReportViewer3.DataBind();
                cmd.Dispose();
                if (Con.State != ConnectionState.Closed)
                    Con.Close();

                return ds.Tables["MORE_DETAILS"];
                //return ;

            }
            catch (OracleException ex)
            {

                Response.Write(ex.ToString());
                return null;
            }
        }



NullReference异常用户代码未处理:对象引用未设置为对象的实例。消息显示。



以下是我的Page_load方法的代码,用于从我的MainReport数据库接收数据的方法... (全部实际上剩下的代码)




NullReference Exception Unhandled by the user code: "Object reference not set to an instance of an object." message is shown.

Following is the code for my Page_load method n the method for receiving data from database for my MainReport... (all of the remaining code actually)

public partial class WebForm1 : System.Web.UI.Page
    {
        public static string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString;
        static OracleConnection Con = new OracleConnection(connectionString);
        OracleCommand cmd = new OracleCommand("", Con);

        DataSet ds = new DataSet();
        dsSample ds10 = new dsSample(); // .xsd file name

        protected void Page_Load(object sender, EventArgs e)
        {
            int id = 0;
            // int rk = 0;
            getAllOrders(id);
            // getSubOrders(id);

            if (Page.IsPostBack == true)
            {
                
                {
                    getSubOrders(id);
                }
            }


        }


        public DataTable getAllOrders(int id)
        {
            try
            {
                //Connection string replace 'databaseservername' with your db server name

                if (Con.State != ConnectionState.Open)
                {
                    Con.Open();

                }

                ReportDocument rptDoc = new ReportDocument();

                //CrystalReportViewer CrystalReportViewer3 = new CrystalReportViewer();

                //CrystalReportViewer CrystalReportViewer1 = new CrystalReportViewer();
                //CrystalReportViewer1.Visible = false;



                //Stored procedure calling. It is already in sample db.               
                cmd.CommandText = "PKG_TEST_BIO.SP_GET_RECEIVED_DATA_PRATIP";
                cmd.CommandType = CommandType.StoredProcedure;
                OracleParameter Para_ID = new OracleParameter("temp_rnk", OracleDbType.Int32);
                OracleParameter Para_RSCUR = new OracleParameter("nreturn", OracleDbType.RefCursor);
                Para_ID.Direction = ParameterDirection.Input;
                Para_ID.Value = id;
                Para_RSCUR.Direction = ParameterDirection.Output;
                cmd.Parameters.Add(Para_ID);
                cmd.Parameters.Add(Para_RSCUR);
                OracleDataAdapter adapter = new OracleDataAdapter(cmd);


                adapter.Fill(ds, "DataTable1");

                DataRow userDetailsRow;
                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    userDetailsRow = ds10.Tables[0].NewRow();
                    userDetailsRow["RNK"] = Convert.ToInt32(row["RNK"].ToString());
                    userDetailsRow["TITLE"] = row["TITLE"].ToString();
                    userDetailsRow["RELEASED"] = Convert.ToInt32(row["RELEASED"].ToString());
                    userDetailsRow["GENRE"] = row["GENRE"].ToString();
                    ds10.Tables[0].Rows.Add(userDetailsRow);
                }
                ds.Tables[0].AcceptChanges();
                rptDoc.Load(HttpContext.Current.Server.MapPath("~/Reports/CrystalReport3.rpt"));

                //set dataset to the report viewer
                rptDoc.SetDataSource(ds10.Tables[0]);

                CrystalReportViewer3.ReportSource = rptDoc;

                cmd.Dispose();
                //if (Con.State != ConnectionState.Closed)
                //    Con.Close();

                return ds.Tables[0];
            }
            catch (Exception ex)
            {
                Response.Write(ex.ToString());
                return null;
            }
        }







是否需要创建差异。数据集的实例或.xsd文件??





顺便说一下,我创建了我的表DataTable1(主要)n dsSample.xsd文件中的MORE_DETAILS(对于子报告)都正确,并且有正确的字段链接。







当在主报表中填充数据时,数据未在子报表的数据集中填充的可能原因是什么?



提前感谢您的帮助! !!




Is there any need to create diff. instances of datasets or the .xsd file??


btw, i've created my tables "DataTable1" (Main) n "MORE_DETAILS" (for subreport) in the dsSample.xsd file all correct with proper links to fields.



what can be the possible reason for data not being populated in the datset for subreport when it's being populated in the mainreport??

Thanks in advance for your HELP!!!

推荐答案

无效的登录详细信息。在运行时动态应用有效的登录详细信息。

C#Crystal Reports动态登录参数 [ ^ ]

还要确保已应用子报告的登录详细信息

添加子报告登录代码 [ ^ ]
Invalid logon details. Apply valid logon details dynamically at run time.
C# Crystal Reports Dynamic Logon parameters[^]
Also make sure you have applied logon details for subreports
Adding the Subreport Logon Code[^]


这篇关于无法在CrystalReports中生成ondemand subReport的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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