How to create Crystal report simple way?
Step1: Right click on Solution,Select Add New Item.
Step2: Select DataSet from Template. Rename DataSet example : StockDataSet.xsd
Step3: Select DataTable from DataSet components and Drag into DataSet design surface.
Step4: Rename the DataTable and add new columns in data table.
Step5: Now Add new item CrystalReport from Reporting Pan.
Step6: Select Standard ReportCreation wizard.
Step7: Expand Project Data. Then expand ADO.NET DataSets. There we can see Data table which we created in DataSet design.
Step8: Select that Datatable and move to Selected Tables.Click Next
Step9: Select the fields from Available Fields Pan and move to Fields To Display Pan.
Step10: Click Finish. After finishing we will get CrystalReportdesign with fields.
Step11: Now Add new Item Web form and rename.
Step12: Drag CrystalReportViewer into Form.
Step13: Double click on CrystalReportViewer And Add following Code in Crystalreportload.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
namespace WindowsFormsTest
{
public partial class StockForm : Form
{
public StockForm()
{
InitializeComponent();
}
private void crystalReportViewer1_Load(object sender, EventArgs e)
{
SqlConnection conn = Common.conn;
conn.Open();
string sql = " select M.Item_Name Item_Name,S.Trans_Date Trans_Date,SUM(S.NofStock) NofStock From Item_Master M inner Join Item_Stock S on M.Item_ID= S.Item_ID Group by M.Item_Name ,S.Trans_Date ";
SqlDataAdapter rd = new SqlDataAdapter(sql, conn);
StockDataSet ds = new StockDataSet(); //Name of data set
rd.Fill(ds, "Stockdtl");
          
conn.Close();
StockCrystalReport objRpt = new StockCrystalReport(); // Name of crystal report
objRpt.SetDataSource(ds.Tables["Stock"]);
crystalReportViewer1.ReportSource = objRpt;
crystalReportViewer1.Refresh();
}
}
}
How to create common class in Project.
Step1: Add new Item Class. Rename the class.
Step2: Add code in class.
Example Code for Sql Connection class.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
namespace WindowsFormsTest
{
class Common
{
static string ConnectionStr = @"Server=Job\MSSQLSERVER2008;Database=Test_Quiz;user=sa;password=password";
public static SqlConnection conn = new SqlConnection(ConnectionStr);
}
}
Step1: Right click on Solution,Select Add New Item.
Step2: Select DataSet from Template. Rename DataSet example : StockDataSet.xsd
Step3: Select DataTable from DataSet components and Drag into DataSet design surface.
Step4: Rename the DataTable and add new columns in data table.
Step5: Now Add new item CrystalReport from Reporting Pan.
Step6: Select Standard ReportCreation wizard.
Step7: Expand Project Data. Then expand ADO.NET DataSets. There we can see Data table which we created in DataSet design.
Step8: Select that Datatable and move to Selected Tables.Click Next
Step9: Select the fields from Available Fields Pan and move to Fields To Display Pan.
Step10: Click Finish. After finishing we will get CrystalReportdesign with fields.
Step11: Now Add new Item Web form and rename.
Step12: Drag CrystalReportViewer into Form.
Step13: Double click on CrystalReportViewer And Add following Code in Crystalreportload.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
namespace WindowsFormsTest
{
public partial class StockForm : Form
{
public StockForm()
{
InitializeComponent();
}
private void crystalReportViewer1_Load(object sender, EventArgs e)
{
SqlConnection conn = Common.conn;
conn.Open();
string sql = " select M.Item_Name Item_Name,S.Trans_Date Trans_Date,SUM(S.NofStock) NofStock From Item_Master M inner Join Item_Stock S on M.Item_ID= S.Item_ID Group by M.Item_Name ,S.Trans_Date ";
SqlDataAdapter rd = new SqlDataAdapter(sql, conn);
StockDataSet ds = new StockDataSet(); //Name of data set
rd.Fill(ds, "Stockdtl");
conn.Close();
StockCrystalReport objRpt = new StockCrystalReport(); // Name of crystal report
objRpt.SetDataSource(ds.Tables["Stock"]);
crystalReportViewer1.ReportSource = objRpt;
crystalReportViewer1.Refresh();
}
}
}
How to create common class in Project.
Step1: Add new Item Class. Rename the class.
Step2: Add code in class.
Example Code for Sql Connection class.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
namespace WindowsFormsTest
{
class Common
{
static string ConnectionStr = @"Server=Job\MSSQLSERVER2008;Database=Test_Quiz;user=sa;password=password";
public static SqlConnection conn = new SqlConnection(ConnectionStr);
}
}
No comments:
Post a Comment