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

D

developers

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
 
D

Dave Anderson

developers said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top