473,387 Members | 1,903 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

ASP Displaying Images from within SQL DB

I've been searching and searching for this and there are lots of posts - but
very few answers.

I have a SQL2000 Database that has jpg images in a table that I want to
display in a webpage. I can return all the other information in the
database except the pictures. I can't take the images out and link them. I
have 2 different results. The code included below gives me a page that says
"This is a picture:" and then box with a red X.

If I change it around I can get a very long page filled with nothing but
jumbled characters.

Can someone please point me to a resolution

Thanks

*****MAIN.ASP********
DIM objConn
Dim objRS
Dim objCommand
Set objConn = Server.CreateObject("ADODB.Connection")
Set objRS = Server.CreateObject("ADODB.Recordset")
Set objCommand = Server.CreateObject("ADODB.Command")
'connection string to SQL Database
objConn.Open "Provider=SQLOLEDB.1;Password=XXXXXXXX;Persist Security
Info=True;User ID=sa;Initial Catalog=test;Data Source=XXXXXXXX"

objCommand.ActiveConnection = objConn
objCommand.CommandText = "SELECT * FROM Sheet1 WHERE Surname LIKE 'Blythe'"
objCommand.CommandType=adCmdText
Set objRS = objCommand.Execute

if objRS.EOF = False Then
While not objRS.EOF
Response.Write objRS("First") & " " & objRS("Surname")& " " & objRS("DOB")
& " " & "<BR>"
objRS.MoveNext
Wend

Else
Response.Write "No Records Found"
end if
%>
This is a Picture:

<IMG alt="" src="ShowPicture.asp">
<%
'close DB Connection and Clean up.
objRS.Close
objConn.Close
Set objCommand = Nothing
Set objRS = Nothing
Set objConn = Nothing
%>
</Body>
</html>

**************ShowPicture.asp************
FILE="C:\Program Files\Common Files\SYSTEM\ADO\msado15.dll" -->
DIM objConn
Dim objRS
Dim objCommand
Set objConn = Server.CreateObject("ADODB.Connection")
Set objRS = Server.CreateObject("ADODB.Recordset")
Set objCommand = Server.CreateObject("ADODB.Command")
'connection string to SQL Database
objConn.Open "Provider=SQLOLEDB.1;Password=XXXXXXXX;Persist Security
Info=True;User ID=sa;Initial Catalog=test;Data Source=XXXXXXXX"

objCommand.ActiveConnection = objConn
objCommand.CommandText = "SELECT picture FROM Sheet1 WHERE Surname LIKE
'Blythe'"
objCommand.CommandType=adCmdText
Set objRS = objCommand.Execute

if objRS.EOF = False Then
Response.ContentType = "image/jpeg"
Response.BinaryWrite objRS("picture")
Else
Response.Write "No Records Found"
end if

'close DB Connection and Clean up.
objRS.Close
objConn.Close
Set objCommand = Nothing
Set objRS = Nothing
Set objConn = Nothing
Jul 19 '05 #1
3 3344
CJM
To be honest I'm not sure how well SQL Server handles BLOBs, but regardless,
I would recommend a different solution:

Store your JPG's in a folder under the web server, and store the path to the
JPG in the DB. Then simple point to the pic from within your ASP:
<IMG alt="" src="<%=objRS("PicturePath"%>">

It will make your code simpler, slicker and more maintainable...

hth

Chris

"Sp33di3" <sp*****@hotmail.com> wrote in message
news:uV**************@TK2MSFTNGP11.phx.gbl...
I've been searching and searching for this and there are lots of posts - but very few answers.

I have a SQL2000 Database that has jpg images in a table that I want to
display in a webpage. I can return all the other information in the
database except the pictures. I can't take the images out and link them. I have 2 different results. The code included below gives me a page that says "This is a picture:" and then box with a red X.

If I change it around I can get a very long page filled with nothing but
jumbled characters.

Can someone please point me to a resolution

Thanks

*****MAIN.ASP********
DIM objConn
Dim objRS
Dim objCommand
Set objConn = Server.CreateObject("ADODB.Connection")
Set objRS = Server.CreateObject("ADODB.Recordset")
Set objCommand = Server.CreateObject("ADODB.Command")
'connection string to SQL Database
objConn.Open "Provider=SQLOLEDB.1;Password=XXXXXXXX;Persist Security
Info=True;User ID=sa;Initial Catalog=test;Data Source=XXXXXXXX"

objCommand.ActiveConnection = objConn
objCommand.CommandText = "SELECT * FROM Sheet1 WHERE Surname LIKE 'Blythe'" objCommand.CommandType=adCmdText
Set objRS = objCommand.Execute

if objRS.EOF = False Then
While not objRS.EOF
Response.Write objRS("First") & " " & objRS("Surname")& " " & objRS("DOB") & " " & "<BR>"
objRS.MoveNext
Wend

Else
Response.Write "No Records Found"
end if
%>
This is a Picture:

<IMG alt="" src="ShowPicture.asp">
<%
'close DB Connection and Clean up.
objRS.Close
objConn.Close
Set objCommand = Nothing
Set objRS = Nothing
Set objConn = Nothing
%>
</Body>
</html>

**************ShowPicture.asp************
FILE="C:\Program Files\Common Files\SYSTEM\ADO\msado15.dll" -->
DIM objConn
Dim objRS
Dim objCommand
Set objConn = Server.CreateObject("ADODB.Connection")
Set objRS = Server.CreateObject("ADODB.Recordset")
Set objCommand = Server.CreateObject("ADODB.Command")
'connection string to SQL Database
objConn.Open "Provider=SQLOLEDB.1;Password=XXXXXXXX;Persist Security
Info=True;User ID=sa;Initial Catalog=test;Data Source=XXXXXXXX"

objCommand.ActiveConnection = objConn
objCommand.CommandText = "SELECT picture FROM Sheet1 WHERE Surname LIKE
'Blythe'"
objCommand.CommandType=adCmdText
Set objRS = objCommand.Execute

if objRS.EOF = False Then
Response.ContentType = "image/jpeg"
Response.BinaryWrite objRS("picture")
Else
Response.Write "No Records Found"
end if

'close DB Connection and Clean up.
objRS.Close
objConn.Close
Set objCommand = Nothing
Set objRS = Nothing
Set objConn = Nothing

Jul 19 '05 #2
I said in my original post that I can't take the images out of the DB.

"CJM" <cj*****@yahoo.co.uk> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
To be honest I'm not sure how well SQL Server handles BLOBs, but regardless, I would recommend a different solution:

Store your JPG's in a folder under the web server, and store the path to the JPG in the DB. Then simple point to the pic from within your ASP:
<IMG alt="" src="<%=objRS("PicturePath"%>">

It will make your code simpler, slicker and more maintainable...

hth

Chris

Jul 19 '05 #3
CJM

"Sp33di3" <sp*****@hotmail.com> wrote in message
news:OD**************@tk2msftngp13.phx.gbl...
I said in my original post that I can't take the images out of the DB.

Apologies... I scanned over the post too quickly!

But I'm curious as to why you can't? I assume it is a constraint
someone\something else is placing on you?

I'm afraid I can't really be any more help; I've never used BLOBs to store
images

Good Luck.

Chris
Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Akbar | last post by:
Hey there, Big-time curiosity issue here... Here's the test code (it's not that long)... it's to display a large number of image links with captions, ideally pulled in from an external file...
6
by: Alec | last post by:
Newbie question. I have a database for displaying the names of bed and breakfasts searched for by the town they are in as below. <?php $result = @mysql_query ("SELECT name FROM...
3
by: Dalan | last post by:
At first I was not certain what could cause Access 97 from displaying most jpeg images, but not all. After further testing, it seemed that all original images of less than 275 pixels per inch or...
0
by: Fronky | last post by:
Hope someone can help. I am still learning, so no laughing please. I am displaying records from a database using Response.Write(""); instead of the usual datagrid method. I am doing it this way...
1
by: David Lozzi | last post by:
Hello, I'm wondering whats the best method to use for displaying several photos' thumbnails. One method I know is to dynamically resize the photo at the time the page is loaded. What does this...
8
by: Jon Weston | last post by:
I'm setting up an Access2003 database with pictures. I put a bound ole picture ctrl on a form that's source is the table that contains the pictures and follow ALL the directions for embedding a...
4
by: redpears007 | last post by:
Hi Again, Throwing this one out to you again as i am not getting anywhere and can find little to no information out there. I am currently displaying images (Jpegs) in access via the routine...
3
by: piercy | last post by:
Hi, i am trying to use a list view to display a list of passed and failed items but the images are not always displaying. Sometimes the images will display fine and others they just will not appear....
1
by: littlealex | last post by:
IE6 not displaying text correctly - IE 7 & Firefox 3 are fine! Need some help with this as fairly new to CSS! In IE6 the text for the following page doesn't display properly - rather than being...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.