Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using ASP to associate images with db entries in SQL

Status
Not open for further replies.

dreamaz

Technical User
Dec 18, 2002
184
CA
Hi,

I am new to ASP and SQL. Im trying to create a site using ASP. I am using Dreamweaver to create the ASP page, and have SQL server w/IIS.

I would like to have users run a query from the page, and the results to display the relevant entries from the SQL database. The database connection works ok, I have setup some sample entries.

My question is, can I associate an image with those entries in the SQL database? how is this done.

Somebody had mentioned here that storing images on the SQL server could be a pain when retrieving and it would be better to have the PATHNAME in the sql database point to the image on the server. How could i do this?

Any help would be appreciated. Also, what would be the best package of tools to get this done.

Thanks folks!!

 
You store the graphic files in their own directory and then call for them through a SQL statement. As you can see the path is outside of the SQL statement. All you are storing in DB is file name.

Try something like...

<%
set rs = Server.CreateObject(&quot;ADODB.Recordset&quot;)
sqlstatement=&quot;SELECT * FROM table WHERE field = 'x'&quot;
rs.Open sqlstatement, &quot;DSN=dataname;UID=;PWD=;&quot;,1,3

If rs.EOF then
rs.close
%>
<div align=&quot;center&quot;><h3>Nothing found in database.<h3></div>

<% Else%>
<table>

<%while not rs.EOF%>
<tr>
<td>

<img src=&quot;/ImageDirectory/<%=rs(&quot;Pic&quot;)%>&quot; width=&quot;200&quot; border=&quot;0&quot;>

</td>
<%
rs.MoveNext
Wend
rs.close

%>
</TR>
</Table> Mike Diaz
tripletpublishing.com
 
Thanks for your answer

can i just put a pathname in a table cell?? I have created a basic table in SQL and added a column called Image path.

Where in the SQL database should the pathname be included?

THanks for your help
 
Also,

What would the datatype be for the column in the table to store the pathname?

Thnx
 
The path is hard coded onto the page, and you can do that within a table cell.

Like:

<TR>
<TD>
<img scr=&quot;/graphics/<%=rs(&quot;Picture&quot;)%>&quot; [pic attributes]>
</TD>
</TR>

Don't forget to add the picture width and hieght. That can also be done through your DB or you can set the size outright. Many of the file upload components allow you to capture the file size, width and hieght.

The column data type should be text.

Mike Diaz...
 
COncerning the datbase side of things, any plain text field will work for you, you don't need anything special because when you get it back you will just be printing the string into the src for the image tag.
I would go with a varchar and then find the longest pathname I will want to store, add about 10 for safety and leave it like that.

-Tarwn ________________________________________________________________________________
Want to get great answers to your Tek-Tips questions? Have a look at faq333-2924
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top