Wednesday, March 21, 2012

Retrieving PDF from MS Sql Database using C#

I am now retrieving the PDF from the database and I am getting an error:

Error 1 'GetImages.GetImage(int)': not all code paths return a value

I have:

int imageid =Convert.ToInt32(Request.QueryString["ACTUAL_IMAGE_PDF"]);

And...

privateSqlDataReader GetImage(int imageid)

{

Sql Statement...

}

Could someone help please??

Can you post the complete code?

|||protectedvoid Page_Load(object sender,EventArgs e)

{

int imageid =Convert.ToInt32(Request.QueryString["ACTUAL_IMAGE_PDF"]);SqlDataReader imageContent = GetImage(imageid);

imageContent.Read();

Response.ContentType = imageContent["ImageType"].ToString();

Response.OutputStream.Write((byte[])imageContent["ImageFile"], 0, System.Convert.ToInt32(imageContent["ImageSize"]));

Response.End();

}

privateSqlDataReader GetImage(int imageid)

{

SqlConnection myConnection =newSqlConnection("Data Source=*********");SqlCommand myCommand =newSqlCommand("Select * From DBO.RIMS_TEST_TABLE Where imageid=@.ImagePDF_Name", myConnection);

SqlParameter imageIDParameter =newSqlParameter("@.ImageId",SqlDbType.Int);

imageIDParameter.Value = imageid;

myCommand.Parameters.Add(imageIDParameter);

myConnection.Open();

}

}

|||

Instead ofprivateSqlDataReader GetImage(int imageid)

make it

private void GetImage(int imageid)

since you are not returning anything!

No comments:

Post a Comment