Print Page | Close Window

Dispaying Pic from Access Database

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=4999
Printed Date: 30 March 2026 at 7:50pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Dispaying Pic from Access Database
Posted By: groq
Subject: Dispaying Pic from Access Database
Date Posted: 13 August 2003 at 2:57pm

Can anyone lead me to some code samples that will allow me to display pictures from an Access database using DNS-less ASP connection in a web browser? Any help or suggestions will be greatly appreciated!

Thank you,

GROQ



-------------
GROQ



Replies:
Posted By: Magic
Date Posted: 13 August 2003 at 3:45pm

Okay it's a long time since I did and Access Development work, but storying images in the database itself has always been a big no no. If for no other reason than the size constraints. (If you really want to do this look at SQL)

The best way, IMHO, is to set up a field that has the path / url to the image (Which can be in a common directory) and then use the path /url (in a var for easy coding) to load the image.

Only one note that I can think of, don't make the path too long (IE: 256 Char or less).

Mark



-------------
- Don't ask me how it works, just be greatful it works!

- Now what does this BIG RED button do?


Posted By: 3BEPb
Date Posted: 13 August 2003 at 3:57pm
Or, what I'm usually doing - define file naming logic, based on their database ID (like picture_221.jpg) and creating binary DB column. There's no significant difference in ASP coding to retrieve picture later with case, described by magic, but DB size become even less.


Posted By: Bunce
Date Posted: 13 August 2003 at 4:34pm

Originally posted by 3BEPb 3BEPb wrote:

Or, what I'm usually doing - define file naming logic, based on their database ID (like picture_221.jpg) and creating binary DB column. There's no significant difference in ASP coding to retrieve picture later with case, described by magic, but DB size become even less.

DB size even less?? If you're storing your images in an Access database it will become enormous!  There are very few legitimate reasons for storing them there.

 



-------------
There have been many, many posts made throughout the world...
This was one of them.


Posted By: Misty
Date Posted: 13 August 2003 at 6:58pm

I personally would not recommend that you store images in an Access database. I recently developed a web application with specials for a client. The client is able to upload pictures to the web site. The pictures are uploaded to a folder on the web server. You will have to ask your hosting company to create a folder that would allow you to upload pictures to. The name of the file is added to the database (ex: ImageName: logo.gif). Would you like to get some sample code?  



Posted By: groq
Date Posted: 13 August 2003 at 9:11pm

Yes, I would love to get some sample codes.  I'm more interesting in displaying the pics in the browser.  Yes, any code will help.  Thank you.

GROQ



-------------
GROQ


Posted By: Misty
Date Posted: 13 August 2003 at 10:23pm

You will need to ask your web hosting company to create a folder on your server where you can upload files to it. You will also need to find out if your web hosting company supports ASP SmartUpload. I hope that this sample code will help.

Take a look at a form that you could create for this application:

<FORM NAME="frmPictures" ACTION="AddPictures.asp" METHOD="post"

onSubmit="return InputIsValid()" ENCTYPE="multipart/form-data">

<TABLE width=400 align=center valign="top" cellpadding=2 cellspacing=0 border=0 bgcolor=#cccccc>

<TR>

<TD align=right><STRONG><font face=arial size=-1>Name </font></STRONG></TD>

<TD><INPUT NAME="txtName" SIZE=30 > </TD>

</TR>

<TR> <TD align="right"><STRONG><font face=arial size=-1>Image</font></STRONG></TD>

'You will browse for an image file on your computer that you would like to upload to your web site:

<TD width="70%"><INPUT TYPE="file" name="file" size="35"></TD></TR>

<tr>

<td align=right>&nbsp;</td>

<td align=middle>

<INPUT

Type=submit

Name=subSubmit Value="Submit">&nbsp;<INPUT id=reset1 name=reset1 style="WIDTH: 74px; HEIGHT: 24px" type=reset value="Clear form">

</td></tr></TABLE></FORM>

 

Here's the sample code for the second page that will add and upload the picture. You will also add a name to the name field in the database.  

<%

' Variables

' *********

Dim mySmartUpload

Dim file

Dim Name

'Declare constants for a recordset that allows adding records

'You can also just include the file ADOVBS.INC to get these constants

Const adLockOptimistic = 3

Const adOpenDynamic = 2

dim connectionString, databaseName, path

dim sqlString

' Object creation

' ***************

Set mySmartUpload = Server.CreateObject("aspSmartUpload.SmartUpload")

' Upload

' ******

mySmartUpload.Upload

SpecialsName = mySmartUpload.Form("txtName")

 

' Connect to the DB

' *****************

' Open a recordset

' ****************

'Start sql string with Join

'Create the recordset

set rs = Server.CreateObject("ADODB.Recordset")

rs.Open sqlString, connectionString, adOpenDynamic, adLockOptimistic

' Select each file

' ****************

For each file In mySmartUpload.Files

' Only if the file exist

' **********************

If not file.IsMissing Then

' Add the current file in a DB field

' **********************************

fic="Upload/" &file.FileName&""

file.SaveAs(fic)

Rs.AddNew

Rs("ImageName") = file.FileName

Rs("Name") = Name

Rs.Update

End If

Next

 

' Destruction

' ***********

rs.Close

Set rs = Nothing

 

You said that you would like to know how to display the picture on a web page. I'll give you some code sample for the web page that will display the picture. You can figure out the code for everything else.

You should have something like this if you want to display a picture from a database:

<a href="Picture.asp?qryID=<%=rs("PictureID")%>"><img src=../Upload/<%= rs("ImageName") %> width="100" height="100" border="0" alt=<%= rs("Name")%>></a>



Posted By: b_bonnett
Date Posted: 14 August 2003 at 4:20am

Note that you will have to remove the onSubmit="return InputIsValid()" code from the form, as you won't have the neccessary Javascript function on your site...

Blair



-------------
Webmaster, http://www.planegallery.net/ - The Plane Gallery
Greetings From Christchurch


Posted By: Misty
Date Posted: 14 August 2003 at 10:12am

Blair,

Thank you for pointing out that the onSubmit="return InputIsValid()" code from the form needed to be removed! I had JavaScript code in my form. But I chose to remove the JavaScript code from this form for the sample code. I forgot to remove the onSubmit="return InputIsValid()" code from the form.



Posted By: MorningZ
Date Posted: 14 August 2003 at 10:36am

and also note that he wasn't looking to save the image to a file like the code 3 replies above depicts, he wants to store the image into the database directly

lots of links/talk from searching google
http://www.google.com/search?sourceid=navclient&ie=UTF-8&oe=UTF-8&q=store+images+into+Access+database - http://www.google.com/search?sourceid=navclient&ie=UTF-8&oe=UTF-8&q=store+images+into+Access+database



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: 3BEPb
Date Posted: 16 August 2003 at 10:39pm
Originally posted by Bunce Bunce wrote:

Originally posted by 3BEPb 3BEPb wrote:

Or, what I'm usually doing - define file naming logic, based on their database ID (like picture_221.jpg) and creating binary DB column. There's no significant difference in ASP coding to retrieve picture later with case, described by magic, but DB size become even less.

DB size even less?? If you're storing your images in an Access database it will become enormous!  There are very few legitimate reasons for storing them there.

You got me wrong, dude (I know, I was wrong, I mean boolean, not binary :)). I mean storing of actual file on HDD, not in database, but database will carry just true/false value for image.




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net