string branchid = ""; protected void Page_Load(object sender, EventArgs e) { branchid= Session["branchid"].ToString(); Response.ContentType = "image/jpeg"; Stream strm = ShowImage(branchid); byte[] buffer = new byte[4096]; int byteSeq = strm.Read(buffer, 0, 4096);
while (byteSeq > 0) { Response.OutputStream.Write(buffer, 0, byteSeq); byteSeq = strm.Read(buffer, 0, 4096); } Image1.imageurl=byteSeq; }
public Stream ShowImage(string branchid) { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Safa"].ConnectionString); string sql = "SELECT imgleft1 FROM tblImages WHERE BranchId = @BranchId"; SqlCommand cmd = new SqlCommand(sql, con); cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@BranchId", branchid); con.Open(); object img = cmd.ExecuteScalar();
try
{ return new MemoryStream((byte[])img); } catch
{ return null; } finally
{ con.Close(); } }
|
hi iam using asp.net with c#
iam retreving image from database but i want to display in
image1.imageurl
but it is not displaying image
can you correct my code
CrishPosted May 16, 2010, 9:17 AM
use below link for you solution image binding from database
http://www.dotnetcurry.com/ShowArticle.aspx?ID=129&AspxAutoDetectCookieSupport=1
Don't forget to Mark Do you like this Answer that solved your problem!