How to export dataset value to PDF without using Gridview?

Posted by Prabu_Spark under ASP.NET on 11/19/2012 | Points: 10 | Views : 2613 | Status : [Member] | Replies : 1
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.


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();
string s;
s = "select * from user_details where name='"+name+"'";
cmd = new SqlCommand(s, con);
sda.SelectCommand = cmd;

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();


protected void Button1_Click(object sender, EventArgs e)//Export to PDF button
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=EmpDetails.pdf");
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);



With regards,


Posted by: Megan00 on: 11/20/2012 [Member] Starter | Points: 25

You can see this project, it can export dataset without datagridview, of course, if people need to export data to excel with datagridview, that is OK. In this project, it can export data from database,listview, command to word ,excel,pdf,html,xml,csv,text,swl etc just give it a try.

Never give up! Smile to the world!

Prabu_Spark, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response