Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Windows Application
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..
 
   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 4-Nov-12 4:11am
manabjn408
Edited 4-Nov-12 4:13am
v2
Comments
GanesanSenthilvel at 4-Nov-12 9:14am
   
Code is highlighted
nkkppp at 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 at 4-Nov-12 10:06am
   
I did it, but it display only the column names of the datatable of the Dataset dataset1 .
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

  Permalink  
Comments
manabjn at 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 at 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 at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  
Comments
manabjn at 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)

  Print Answers RSS
0 DamithSL 365
1 Maciej Los 232
2 OriginalGriff 213
3 BillWoodruff 79
4 Jose Garcia Sevilla 75
0 OriginalGriff 7,953
1 DamithSL 6,139
2 Sergey Alexandrovich Kryukov 5,454
3 Maciej Los 5,293
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web01 | 2.8.141223.1 | Last Updated 4 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100