images from database

Discussion in 'ASP .Net' started by cashdeskmac, Mar 11, 2009.

  1. cashdeskmac

    cashdeskmac Guest

    Hi,

    I have a set of images in a database and I am using a DataReader to retrive
    them:

    SqlDataReader dr = command.ExecuteReader();
    if (dr.Read())
    {

    Byte[] b = (Byte[])dr["img_data"];
    MemoryStream ms = new MemoryStream(b);
    Image img = Image.FromStream(ms);
    //create the html for the span
    imageholder.InnerHtml = "";
    }

    Now that I have the Image, how can I assign it to the InnerHtml of the span
    called imageholder (which has the attribute runat="server")?
     
    cashdeskmac, Mar 11, 2009
    #1
    1. Advertising

  2. There is no inner html for image. Instead, there is an image source
    attribute. You should put your code into a separate GetImage.aspx page that
    will have no markup and call it like this:

    <img ... src="GetImage.aspx?id=myImageId" />


    --
    Eliyahu Goldin,
    Software Developer
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin


    "cashdeskmac" <> wrote in message
    news:...
    > Hi,
    >
    > I have a set of images in a database and I am using a DataReader to
    > retrive
    > them:
    >
    > SqlDataReader dr = command.ExecuteReader();
    > if (dr.Read())
    > {
    >
    > Byte[] b = (Byte[])dr["img_data"];
    > MemoryStream ms = new MemoryStream(b);
    > Image img = Image.FromStream(ms);
    > //create the html for the span
    > imageholder.InnerHtml = "";
    > }
    >
    > Now that I have the Image, how can I assign it to the InnerHtml of the
    > span
    > called imageholder (which has the attribute runat="server")?
     
    Eliyahu Goldin, Mar 11, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest
    Replies:
    4
    Views:
    924
    Eliyahu Goldin
    Jan 4, 2005
  2. Luis Esteban Valencia Muñoz
    Replies:
    0
    Views:
    803
    Luis Esteban Valencia Muñoz
    Jun 3, 2005
  3. wardemon

    Cache Images vs Static Images

    wardemon, Jun 14, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    679
    bruce barker
    Jun 14, 2007
  4. Keith Hughitt
    Replies:
    6
    Views:
    1,103
  5. Adrienne Boswell
    Replies:
    1
    Views:
    526
    dorayme
    Aug 4, 2009
Loading...

Share This Page