Hi sir,
I want to export the dataset value to PDF without using Gridview. I typed the below code
but the data is not exporting. Kindly give me the solution for this problem.
Code:
**********************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using PdfSharp;
using PdfSharp.Drawing;
using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;
using sharpPDF;
public partial class Success : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(@"Data Source=lbit00046;Initial Catalog=checking;User ID=sa;password=welcome");
SqlCommand cmd;
public static DataSet ds;
protected void Page_Load(object sender, EventArgs e)
{
if (Session["name"] != null)
{
string name=Session["name"].ToString();
ds = new DataSet();
SqlDataAdapter sda = new SqlDataAdapter();
con.Open();
string s;
s = "select * from user_details where name='"+name+"'";
cmd = new SqlCommand(s, con);
sda.SelectCommand = cmd;
sda.Fill(ds);
lbl_name.Text = ds.Tables[0].Rows[0]["name"].ToString();
lbl_fname.Text = ds.Tables[0].Rows[0]["fname"].ToString();
lbl_age.Text = ds.Tables[0].Rows[0]["age"].ToString();
lbl_sex.Text = ds.Tables[0].Rows[0]["sex"].ToString();
lbl_nationality.Text = ds.Tables[0].Rows[0]["nationality"].ToString();
lbl_caste.Text = ds.Tables[0].Rows[0]["caste"].ToString();
lbl_address.Text = ds.Tables[0].Rows[0]["address"].ToString();
con.Close();
}
}
protected void Button1_Click(object sender, EventArgs e)//Export to PDF button
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=EmpDetails.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
string s1 = ds.Tables[0].Rows[0]["name"].ToString();
sw.WriteLine("Name: " + ds.Tables[0].Rows[0]["name"].ToString());
HtmlTextWriter hw = new HtmlTextWriter(sw);
Response.End();
}
With regards,
J.Prabu.
[Email:prbspark@gmail.com]