create database dbcrytalreport
use dbcrytalreport
create table tbl_employee
(
emp_id int identity primary key,
emp_name nvarchar(20) not null,
emp_salary int not null,
emp_contact nvarchar(20)
)
insert into tbl_employee
values('ali',50000,'03432145678')
insert into tbl_employee
values('ahmed',40000,'03421145678')
insert into tbl_employee
values('bilal',30000,'03412145678')
insert into tbl_employee
values('basit',50000,'03442145678')
select * from tbl_employee
---------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using CrystalDecisions.CrystalReports.Engine;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{//Data Source=.;Initial Catalog=dbcrytalreport;User ID=sa;Password=***********
ReportDocument rd = new ReportDocument();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=dbcrytalreport;User ID=sa;Password=aptech");
SqlDataAdapter da = new SqlDataAdapter("select * from tbl_employee", conn);
conn.Open();
DataSet ds = new DataSet();
da.Fill(ds,"employee");
rd.Load(@"C:\Users\salman\documents\visual studio 2013\Projects\WindowsFormsApplication1\WindowsFormsApplication1\CrystalReport1.rpt");
rd.SetDataSource(ds);
crystalReportViewer1.ReportSource = rd;
}
}
}
--------------------------------------------------------------------------------------------------