Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)

how i retrieve pdf files in gridview using mssql 2008 and in Database i use varchar(max) instead of varbinary(max) in sql 2008 server ; it gives error "how to convert system.string to system.byte[] " .... PLZ HELP




----------------------------------------------------------------------------------







using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.IO;
using System.Text;
using System.Net;

public partial class Defaultpdf : System.Web.UI.Page
{
SqlConnection sqlcon = new SqlConnection("Data Source=;Initial Catalog=;User ID=;Password=");
SqlCommand cmd = new SqlCommand();
SqlDataAdapter da = new SqlDataAdapter();
DataTable dt = new DataTable();
string qstr;
byte[] b = null;



protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
qstr = Request.QueryString["ReqDocId"];

SqlCommand sqlcmd = new SqlCommand("Select ReqDoc from tbl_name where ReqDocId='" + qstr + "'", sqlcon);
sqlcon.Open();
da = new SqlDataAdapter(sqlcmd);
da.Fill(dt);
if (dt.Rows.Count > 0)
{
b =((byte[])dt.Rows[0][0]);


Response.ContentType = "application/pdf";

Response.BinaryWrite(b);
}
}
}



}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900