I wan't your help in Inserting and selecting image from DB

Discussion in 'ASP General' started by developers, May 1, 2006.

  1. developers

    developers Guest

    Hello Every One ,
    I need Help in inserting the user image in my data base. but
    unfortunatly I don't know how.I'm using asp with sql server. I tried to
    insert the image and i geuss it worked.for the field in the db in not
    null and it have this value <Binary> . but when i try to select it in
    gives me this error "An unhandled data type was encountered".
    this is my code :

    To insert the image
    sql="insert into users_img (user_image,user_id) values
    ('"&image&"','"&userid&"')"
    set rs=conn.Execute (sql)

    to Select the image :
    sql="select * from users_img where user_id='"&userid&"'"
    set rs=conn.Execute (sql)
    Response.ContentType = "image/jpg"
    Response.BinaryWrite rs("adv_image")

    Realy Need Your help
    thanx alot
    Yours, Maii Ali


    *** Sent via Developersdex http://www.developersdex.com ***
    developers, May 1, 2006
    #1
    1. Advertising

  2. developers wrote:
    > I need Help in inserting the user image in my data base. but
    > unfortunatly I don't know how.I'm using asp with sql server. I tried
    > to insert the image and i geuss it worked.for the field in the db in
    > not null and it have this value <Binary> . but when i try to select
    > it in gives me this error "An unhandled data type was encountered".
    > this is my code :
    >
    > To insert the image
    > sql="insert into users_img (user_image,user_id) values
    > ('"&image&"','"&userid&"')"
    > set rs=conn.Execute (sql)


    I don't think you can insert the image as text. This is almost certainly
    your problem.



    > to Select the image :
    > sql="select * from users_img where user_id='"&userid&"'"
    > set rs=conn.Execute (sql)
    > Response.ContentType = "image/jpg"
    > Response.BinaryWrite rs("adv_image")


    1. If you are only going to use [adv_image], why select [*] ?
    2. Test for existence.
    3. Default properties hurt my eyes. Get in the habit of using explicitly
    named ones.
    4. When your browser *uploads* JPG images, it sends "image/jpeg", not
    "image/jpg", so you should send it back the same way.

    Set rs = conn.Execute(sql)
    If NOT rs.EOF Then
    Response.ContentType = "image/jpeg"
    Response.BinaryWrite(rs.Fields("adv_image").Value
    Else
    Response.Redirect("NotFound.jpg")
    End If



    --
    Dave Anderson

    Unsolicited commercial email will be read at a cost of $500 per message. Use
    of this email address implies consent to these terms.
    Dave Anderson, May 1, 2006
    #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. ben
    Replies:
    2
    Views:
    2,082
    Guest
    Dec 24, 2003
  2. hibiki
    Replies:
    2
    Views:
    433
    hibiki
    Apr 13, 2005
  3. hibiki
    Replies:
    0
    Views:
    334
    hibiki
    Apr 12, 2005
  4. Frogleg

    Help me, Obi-Wan Kenobi

    Frogleg, Jun 16, 2004, in forum: HTML
    Replies:
    15
    Views:
    635
  5. Tom Thorpe
    Replies:
    3
    Views:
    323
    Mark McIntyre
    Apr 19, 2005
Loading...

Share This Page