Click here to Skip to main content
15,881,413 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I am developing a windows application using C# Vs2008 . I need to create dynamic crystal report.
To create the dynamic crystal report, first I add a dataset and then a datatable to the dataset. Now I add 4 columns to the datatable.
Now I add a crystal report and bind the crystal report with the datatable of the dataset. Now I take a crystalreportviewer and bind the crystalreport with the crystal reportviewer. The following code i used..

C#
private void button1_Click(object sender, EventArgs e)
     {
         CrystalReport1 objRpt = new CrystalReport1();
         con.Open();
         SqlCommand cmd=new SqlCommand("select pro_id,pro_nm,quantity,total from bill_t ",con);
         SqlDataAdapter da=new SqlDataAdapter(cmd);
         DataSet1 ds = new DataSet1();
         da.Fill(ds, "bill_t");
         objRpt.SetDataSource(ds.Table[1]);
         crystalReportViewer1.ReportSource = objRpt;
         crystalReportViewer1.Refresh();
         con.Close();

     }
I did not get any error, only crystal report does not show anything.
So, Please help me to solve this problem.
Posted
Updated 4-Nov-12 3:13am
v2
Comments
Ganesan Senthilvel 4-Nov-12 9:14am    
Code is highlighted
Prathap Gangireddy 4-Nov-12 9:54am    
Hi Dude,

I think you need to change the code to

objRpt.SetDataSource(ds.Table[0]); as you are referring to table at index 0

Regards,
Prathap.
manabjn 4-Nov-12 10:06am    
I did it, but it display only the column names of the datatable of the Dataset dataset1 .

 
Share this answer
 
Comments
manabjn 4-Nov-12 14:16pm    
I follow the all steps whatever you mentioned, but still it remain unchanged............
anyway thank for your kind help
Khalid Farhan 5-Nov-12 5:10am    
Would you give detail...What is happening? Use debugging to get is there report file & data getting or not.
manabjn 5-Nov-12 10:41am    
whenever I debug my project ,dataset is loaded with new table bill_t with my required data. Thus at runtime , dataset DataSet1 has two table, one is DataTable1(which is created at designing time of Dataset1) and other one is bill_t. Upto this everything is seems to be right.
objRpt.SetDataSource(ds.Tables[1]);
crystalReportViewer1.ReportSource = objRpt;//where obj is the object the Crystal report CrystalReport1
I think above two line of codes have some mistake..
Please Help me
 
Share this answer
 
Comments
manabjn 4-Nov-12 14:39pm    
objRpt.SetDataSource(ds);
crystalReportViewer1.ReportSource = objRpt;
//objRpt is the object of Crystal report...
I dont know where is the fault.
Either on first line or second line must have the fault. Dataset fill with data but i dont khow what to do now.. Plz help me

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