Click here to Skip to main content
15,881,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
C#
private void MyReport_Load(object sender, EventArgs e)
        {
            ReportDocument rptDoc = new ReportDocument();
            FileDataSet1 ds = new FileDataSet1(); // .xsd file name
            DataTable dt = new DataTable();

            dt.TableName = "Crystal Report Example";
            dt = getAllOrders(); //This function is located below this function
            ds.Tables[0].Merge(dt);

            try
            {
                string rPath = Directory.GetCurrentDirectory();
                int index = rPath.ToLower().IndexOf("bin");
                if (index >= 0)
                {
                    rPath = rPath.Substring(0, index);
                }
                rPath = rPath + @"FileMenu\CrystalReport2.rpt";
                
                rptDoc.Load(rPath);
                rptDoc.SetDataSource(ds);
                crystalReportViewer1.ReportSource = rptDoc;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }

        public DataTable getAllOrders()
        {
            string sqlCon = ".....";
            SqlConnection Con = new SqlConnection(sqlCon);
            SqlCommand    cmd = new SqlCommand();
            DataSet ds = null;
            SqlDataAdapter adapter;
            try
            {
                Con.Open();
                cmd.CommandText = "select * from Account_Details";
                cmd.Connection = Con;
                ds = new System.Data.DataSet();
                adapter = new SqlDataAdapter(cmd);
                adapter.Fill(ds, "Users");
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                cmd.Dispose();
                if (Con.State != ConnectionState.Closed)
                    Con.Close();
            }
            return ds.Tables[0];
        }

This code is run well in VS2010. But when i create an .exe file of this project the report file could not load by showing an error message "Load Report Failed".

Need Help for this issue.
Posted
Updated 29-Mar-13 4:18am
v4
Comments
ZurdoDev 29-Mar-13 11:14am    
Are there more details to the error?
Chiranjib Chowdhury 29-Mar-13 13:34pm    
No. only "Load Report Failed".
ZurdoDev 29-Mar-13 13:57pm    
It's likely either it can't be found or permissions issue. http://social.msdn.microsoft.com/Forums/en-US/vscrystalreports/thread/438b3ee8-9854-40b8-ac8f-cadbabff455d

1 solution

 
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