0
Answer

displaying selected image from database in a new web page

Ask a question
ds ps

ds ps

14y
2.4k
1

on click on selected image, new page will display the image stored in the database table,so on page load event i 've following codes.. but there is error with response.binarywrite(.....
can anyone help me to make it right??i tried so many times..but not succeed...plz help
 
protected
void Page_Load(object sender, EventArgs e)
{

int
PictureID = 1;
//Connect to the database and bring back the image contents & MIME type for the specified picture
string ConStr = System.Configuration.ConfigurationSettings.AppSettings.Get("SQLCON").ToString();
SqlConnection cn = new SqlConnection(ConStr);
//cn.Open();
// string SQL = "INSERT INTO ContractImages (ContractId, PartyConrNum ,Title, UploadDate, MIMEType, ImageData) VALUES (@Title, @MIMEType, @ImageData)"
string SQLQRY = "SELECT [MIMEType], [ImageData] FROM ContractImages WHERE [ImageId] = @PictureID";
SqlCommand cmd = new SqlCommand(SQLQRY, cn);
cmd.Parameters.AddWithValue(
"@PictureID", PictureID); //PictureTitle.Text.Trim());
cn.Open();
SqlDataReader imagereader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
while (imagereader.Read())
{
Response.ContentType = imagereader[
"MIMEType"].ToString ();
Response.BinaryWrite(imagereader[
"ImageData"]);

}
imagereader.Close();
cn.Close();
}

Next Recommended Forum