Hello Meenakshi,
Just Refer the Below Example.
step 1:- Add New Form and Drag & Drop the CrystalReportViewer and set its Dock property to Fill.
step 2:- Now Right Click on your Project and Click on add New Item (Ctrl+shift+a), After open Popup Choose the Reporting tab from vertical tab and select the CrystalReport.
e.g. "crystalreport1.rpt"
step 3:- After that, Right Click on your Project and Click on add New Item (Ctrl+shift+a), After open Popup Choose the Data tab from vertical tab and set Dataset.
e.g. "DataSet1.xsd"
step 4:- Now Just Right Click and Add datatable then Add the Column to that Datatable.
e.g I have use the Column name Such as "empID","empName","address","city","contactNo".
step 5:- After that Click on crystalreport1.rpt and Just go Field Explorer & Right Click on Database Fields and select Database expert and go in ProjectData and add Datatable Now expand the Database field and Datatable Your Database Field is ready to use.
step 6:- Now Drag and Drop Database Field From Datatable and put in section3(Details) of Crystal Report1.rpt.
Now Do the Following Code :-
private void crystalReportViewer1_Load(object sender, EventArgs e)
{
ReportDocument rd;
DataSet1 ds = new DataSet1();
DataTable dt = ds.Tables["DataTable1"];
DataRow dr;
for (int i = 1; i <= 100; i++)
{
dr = dt.NewRow();
dr["empID"] = i;
dr["empName"] = "John Carry";
dr["address"] = "Street 001, Rivera Green, CA";
dr["city"] = "Tracy";
dr["contactNo"] = "9876543210";
dt.Rows.Add(dr);
}
rd = new CrystalReport1();
rd.SetDataSource(dt);
crystalReportViewer1.ReportSource = rd;
crystalReportViewer1.Refresh();
}