Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more: , +
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

C#
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 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)

C#
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;
            }
        }



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!!!
Posted
Updated 30-Apr-12 2:40am
v4
Comments
The Doer 27-Apr-12 8:31am    
yes Its must to create a typed dataset(.xsd) This dataset ll be loaded into the report docunment then the report document will be binded to the Crystal Report Viewer.
Here the .xsd dataset should contains the same column name as of the column name in your table in the database.
Refer these point you may find some way ..

1 solution

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[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900