Tech
Forums
Jobs
Books
Events
Live
Interviews
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
0
Reply
how i retrieve pdf files in gridview using mssql 2008
amit
Dec 31 2014 1:29 AM
456
Reply
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);
}
}
}
}
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
0
)
Next Recommended Forum
I want to create web portal like IP Messenger in MVC
Unabletocastobjectoftype 'System.String' totype 'System.byte