kishor choure

kishor choure

  • NA
  • 87
  • 46.2k

Crystal Report generates error

Jul 31 2012 11:58 AM
I want to create crystal report with  sql query. For that I am trying following code 
inside button1_click event in C# windows application. But In this code I get an error 
that "Invalid path of crystal report".




  private void button1_Click(object sender, EventArgs e)
        { 
        string str = "select s_first,s_last,s_dob,c_sem,c_year from personaltbl,coursetbl         where personaltbl.r_id = coursetbl.r_id and coursetbl.c_name='MCA'";
                scmd.CommandText = str;
                scmd.Connection = scon;

                if (scon.State == ConnectionState.Closed)
                    scon.Open();

                sdap = new SqlDataAdapter(scmd);
                
                sdap.Fill(ds, "personal");

                ReportDocument rd = new ReportDocument();
                rd.SetDataSource(ds.Tables["personal"]);
                rd.Load(@"~/First_Report.rpt");//I also used @"c:\project\project_first\first_Report.rpt"
              
                rd.SetDataSource(ds.Tables["personal"]);
                crystalReportViewer1.ReportSource = rd;
                crystalReportViewer1.RefreshReport();
                if (scon.State == ConnectionState.Open)
                            scon.Close();

            }
            catch (Exception ex)
            {
                MessageBox.Show(" exce :" + ex.Message );
            }
}        
Please tail me  the simple code to display report using sql query.

Answers (3)