Hai,
I'm using VS2010 and SQL Server2005.
I'm creating Salary Slip using Crystal Report in my project. Its run successfully and display the record in Crystal Report what I Needed.
and the Next thing is i want to take print out from that report and Export That record to what i needed fromat(Pdf 0r Word or Execl).
See below my code for displaying crystal report:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
fillddl();
}
}
public void fillddl()
{
SqlConnection con = new SqlConnection("Data Source=SERVICETEAM-PC;Initial Catalog=salaryReg;User ID=sa;Password=kavi");
con.Open();
SqlCommand com = new SqlCommand("select empName from SalaryEarnings ", con);
SqlDataReader dr = com.ExecuteReader();
ddlUserName.Items.Clear();
while (dr.Read())
{
ddlUserName.Items.Add(new ListItem(dr[0].ToString()));
}
ddlUserName.Items.Insert(0, new ListItem("--Select--", "0"));
con.Close();
}
protected void btnShow_Click(object sender, EventArgs e)
{
btnExport.Visible = true;
dssample ds = new dssample(); // .xsd file name
DataTable dt = new DataTable();
dt.TableName = "Crstal Report";
dt = GetAllOrders();
ds.Tables[0].Merge(dt);
if (ds.Tables[0].Rows.Count > 0)
{
rptDoc.Load(Server.MapPath("~/CrystalReport.rpt"));
rptDoc.SetDataSource(ds);
CrystalReportViewer1.ReportSource = rptDoc;
CrystalReportViewer1.RefreshReport();
}
else
{
Response.Write("<script type=\"text/javascript\">alert('No record found for the month & year!...');</script>");
}
}
public DataTable GetAllOrders()
{
SqlConnection cn = new SqlConnection("Data Source=SERVICETEAM-PC;Initial Catalog=salaryReg;User ID=sa;Password=kavi");
SqlCommand cmd = new SqlCommand("Select * from SalaryEarnings where empName='" + ddlUserName.Text + "' and Salary_Year='"+ddlSalaryYear.Text+"' and Salary_Month='"+ddlSalayMonth.Text+"'", cn);
DataSet ds = null;
SqlDataAdapter da;
try
{
cn.Open();
ds = new DataSet();
da = new SqlDataAdapter(cmd);
da.Fill(ds, "User");
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
cmd.Dispose();
if (cn.State != ConnectionState.Closed)
cn.Close();
}
return ds.Tables[0];
}
Note: I want to know how to Export the report and take print out of that record....