By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,446 Members | 2,998 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,446 IT Pros & Developers. It's quick & easy.

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

P: n/a


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 ***
May 1 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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.
May 1 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.