Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
string SQL = "SELECT * FROM DPSpdf WHERE intpdfId='" + txtdanceid.Text + "'";
        SqlCommand myCommand = new SqlCommand(SQL, (SqlConnection)Application.Get("DPS"));
        myCommand.Parameters.AddWithValue("@intpdfId", txtdanceid.Text);
 
        SqlDataReader myReader = myCommand.ExecuteReader();
 
        if (myReader.Read())
        {
            Response.ContentType = myReader["ContentType"].ToString();
            Response.BinaryWrite((byte[])myReader["strpdfurl"]);
 
        }
 
        myReader.Close();
        Response.End();
 
Where i did mistake?
Posted 6-Feb-11 19:31pm
Rupa11.4K
Edited 6-Feb-11 19:32pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Server Error in '/WebSite2' Application.
ExecuteReader: Connection property has not been initialized.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,
 
You are passing inline parameter and command parameter at a time. You need to choose one of them, better choice is passing command parameter instead of inline value.
 
Please see the modified sql statement below,
 
string SQL = "SELECT * FROM DPSpdf WHERE intpdfId=@intpdfId";
SqlCommand myCommand = new SqlCommand(SQL, (SqlConnection)Application.Get("DPS"));
myCommand.Parameters.AddWithValue("@intpdfId", txtdanceid.Text);
SqlDataReader myReader = myCommand.ExecuteReader();
if (myReader.Read())
{
   Response.ContentType = myReader["ContentType"].ToString();
   Response.BinaryWrite((byte[])myReader["strpdfurl"]);
}
 
myReader.Close();
Response.End();
  Permalink  
Comments
1nagaswarupa at 7-Feb-11 1:51am
   
sir not coming where i am doing mistake?
Shahriar Iqbal Chowdhury at 7-Feb-11 2:00am
   
did u debug the code? is data returned from db?
1nagaswarupa at 7-Feb-11 4:36am
   
The XML page cannot be displayed
Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.
 

--------------------------------------------------------------------------------
 
An invalid character was found in text content. Error processing resource 'http://localhost:3055/DPS/testpdf.aspx'. Line 2...
 
%
 
ya finally coming error this one sir where i am doing mistake.......
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Try this code
 

System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
byte[] data = (byte[])myReader["strpdfurl"];
System.Web.HttpResponse Response = System.Web.HttpContext.Current.Response;
 
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = myReader["ContentType"].ToString();
Response.AddHeader("content-disposition", "attachment;filename=" + "Test" + ".pdf");
Response.BinaryWrite(data);
Response.Flush();
Response.End();
  Permalink  
Comments
1nagaswarupa at 7-Feb-11 2:33am
   
string SQL = "SELECT * FROM DPSpdf WHERE intpdfId=@intpdfId";
SqlCommand myCommand = new SqlCommand(SQL, (SqlConnection)Application.Get("DPS"));
myCommand.Parameters.AddWithValue("@intpdfId", txtdanceid.Text);
SqlDataReader myReader = myCommand.ExecuteReader();
if (myReader.Read())
{

byte[] data = (byte[])myReader["strpdfurl"];
System.Web.HttpResponse Response = System.Web.HttpContext.Current.Response;
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = myReader["ContentType"].ToString();
Response.BinaryWrite(data);
myReader.Close();
Response.End();


}
i implemented like this but not showing pdf file sir................
1nagaswarupa at 7-Feb-11 2:34am
   
in binary data coming data but it's not able to write data
soni uma at 7-Feb-11 2:41am
   
I think there is problem in what you store into database. Because the code i give you is working example. Check your code that you store data into binary format.
1nagaswarupa at 7-Feb-11 2:45am
   
ya i gave data field strpdfurl as varbinary(MAX) is it wrong?
soni uma at 7-Feb-11 2:51am
   
yes wrong. If you use Mysql than use LongBlob if Mssql than
use binary or search on that.
soni uma at 7-Feb-11 2:56am
   
Oh i am sorry. If you take varbinary(Max) than it is ok
1nagaswarupa at 7-Feb-11 3:00am
   
shell i keep binary(50) it's ok.......
soni uma at 7-Feb-11 3:51am
   
Try with it.
1nagaswarupa at 7-Feb-11 4:35am
   
ok i keep varbinary(Max) but coming error in output page
 

The XML page cannot be displayed
Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.
 

--------------------------------------------------------------------------------
 
An invalid character was found in text content. Error processing resource 'http://localhost:3055/DPS/testpdf.aspx'. Line 2...
 
%
 

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

  Print Answers RSS
0 OriginalGriff 324
1 Maciej Los 224
2 Sergey Alexandrovich Kryukov 182
3 Richard MacCutchan 120
4 CPallini 120
0 OriginalGriff 5,474
1 Sergey Alexandrovich Kryukov 4,713
2 Peter Leow 2,944
3 DamithSL 2,465
4 Maciej Los 2,434


Advertise | Privacy | Mobile
Web02 | 2.8.140718.1 | Last Updated 17 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid