Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to export stored procedure to PDF using ASP.NET 4.0 with C# and VS2010?

Status
Not open for further replies.

krz9

Programmer
Dec 10, 2013
1
0
0
US
How to export a stored procedure to PDF using ASP.NET 4.0 with C# and VS2010?

I tried the following code but get error:
Adobe Reader could not open 'xxx.PDF' because it is either not a supported file or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded).
------------------------

protected void Button1_Click1(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
string query = "proc_SMR_EDIT_OI_BYRPTNAME";
var cmd = new SqlCommand(query, conn);
cmd.CommandType = CommandType.StoredProcedure;
conn.Open();
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
var reader = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(reader);
ExportTableData(dt);
}


protected void ExportTableData(DataTable dtdata)
{
string attachment = "attachment; filename=Contacts.pdf";

Response.ClearContent();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", attachment);
Response.End();
}

public override void VerifyRenderingInServerForm(Control control)
{

}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top