codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Image issue  belord at 23:29 on Tuesday, December 14, 2004
 

I am using asp 3.0 and sql server 2000 for my application.

The problem i am having is with displaying images from database in the database the datatype of the field is image and field name is Cover_Picture.





<%
Option Explicit
Response.Buffer=True
%>
<!-- #Include virtual="/media/doctype.txt" -->
<html>
<head>
<!-- #Include virtual="/metatags.htm" -->
<!-- #Include virtual="/includestyles.htm" -->
<title>Shopping Store </title>
</head>
<body>
<!--#Include virtual="/media/header2.htm" -->
<div class="content">
<%
dim str
str="Yes"
Dim Conn, strDSN,rsobjfea, strSQLfea
Set Conn = Server.CreateObject("ADODB.Connection")
strdsn is my connection string which works fine i just removed it for security purposes
Conn.Open strDSN

Set rsobjfea = Server.CreateObject("ADODB.Recordset")
strSQLfea="select Large_Picture,Sub_Item, Description from Products_Details1 where Featured='" & str & "'"
rsobjfea.Open strSQLfea, Conn, 2,2
%>


<h1>Featured Items !</h1>
<table cellpadding="10px" >
<%
Do while not rsobjfea.eof
%>
<tr>
<th colspan="2"><%=rsobjfea.Fields("Sub_Item")%></th>
</tr>
<tr>

<td valign="top">
<%
'Response.ContentType = "image/jpeg"
%>
<img name="ProductPhoto"
src="<% Response.BinaryWrite rsobjfea("Large_Picture") %>"
width="144" height="144" /></td>
<td valign="top"><%=rsobjfea.Fields("Description")%></td>
</tr>
<%
rsobjfea.MoveNext
Loop
%>
</table>
</div>

<div class="navigation">
<!--#include file="/forum/navigation.html" -->
</div>
</body>
</html>


I dont know why i cant see the image i have tried removing the image tag and inserting Response.Binarywrite it doesnt work.

thanks in advance.

Belord

  Re: Image issue  tgreer at 23:45 on Tuesday, December 14, 2004
 

It's been a LONG time since I coded classic ASP, and I never worked with images when I did. So, my advice in this case may not be worth much.

But, I've done similar work in ASP.NET. What I do there is create a separate page to retrieve an image and write it out to the response stream.

Then, I set my img "src" equal to that second page. It works very well, and the same technique may work in ASP.

The nice thing about it is you can have ONE page that handles all the work with images, and that page can produce different images based on the querystring passed into it, and can even produce thumbnails, too.



  Re: Image issue  belord at 16:02 on Wednesday, December 15, 2004
 

Hi,

i tried putting the image tag and its still not working


<%
Option Explicit
'Response.Buffer = True

%>
<!-- #Include virtual="/media/doctype.txt" -->
<html>
<head>
<!-- #Include virtual="/metatags.htm" -->
<!-- #Include virtual="/includestyles.htm" -->
<title> NSCA Shopping Store </title>
</head>
<body>
<!--#Include virtual="/media/header2.htm" -->
<div class="content">
<%
dim str
str="Yes"

Dim Conn, strDSN,rsobjfea, strSQLfea
Dim rsimg,strimg

Set Conn = Server.CreateObject("ADODB.Connection")
strDSN = "Provider=SQLOLEDB.1;Password=1234;User ID=sql user;Data Source=BARBELL;Initial Catalog=OnlineStore;"
Conn.Open strDSN

Set rsobjfea = Server.CreateObject("ADODB.Recordset")
strSQLfea="select Large_Picture, Sub_Item, Description from Products_Details1 where Featured='" & str & "'"
rsobjfea.Open strSQLfea, Conn
Response.ContentType="image/jpeg"

%>
<p>Welcome to the NSCA Online Store. You can find educational literature, multimedia materials, helpful organizational items as well as clothing to be enjoyed by all exercise enthusiasts. Members can receive member pricing by <a href = "https://www.nsca-lift.org/secure/MemberStore/home.asp" title="Go to the member store">logging in here</a>. Please enjoy your shopping trip with us and come back often. <a href="/forum/nmsearch.html" title="Use the search form">::Search the store</a></p>

<p>We do not support online ordering for international orders at this time. If you are located outside the United States, please call toll free 1-800-815-6826 to place your order.</p>


<h1>Featured Items !</h1>

<table cellpadding="10px" >
<%
Do while not rsobjfea.eof
%>

<tr>
<th colspan="2"><%=rsobjfea.Fields("Sub_Item")%></th>
</tr>
<tr>

<td valign="top"><img id="<%=rsobjfea.Fields("Sub_Item")%>"
name="<%=rsobjfea.Fields("Sub_Item")%>"
src="<%= rsobjfea("Large_Picture")%>"
alt="<%=rsobjfea.Fields("Sub_Item")%>"
/>
</td>
<td valign="top"><%=rsobjfea.Fields("Description")%></td>
</tr>

<%

rsobjfea.MoveNext
Loop
%>
</table>

</div>


<div class="navigation">
<!--#include file="/forum/navigation.html" -->
</div>
</body>
</html>




  Re: Image issue  tgreer at 16:10 on Wednesday, December 15, 2004
 

Are you willing to try the technique I suggested?



  i tried this one also its still not working  belord at 17:11 on Wednesday, December 15, 2004
 

hi,
it shows me the red icon as a image

<%
Option Explicit
Response.Buffer=True
dim rs
Dim cn
%>
<!-- #Include virtual="/media/doctype.txt" -->
<html>
<head>
<!-- #Include virtual="/metatags.htm" -->
<!-- #Include virtual="/includestyles.htm" -->
<title>Shopping Store </title>
</head>
<body>
<!--#Include virtual="/media/header2.htm" -->
<div class="content">
<%
Function getTempFolder()

Dim fso
Set fso = Server.CreateObject("Scripting.FileSystemObject")
getTempFolder = fso.GetSpecialFolder(2).Path
End Function
%>
<%
Public Function WriteBlobToFile(strImage)
dim mStream, sTemporaryFolder, sFullPath
sTemporaryFolder = getTempFolder & "\"



Set mstream = Server.CreateObject("ADODB.Stream")
mstream.Type = 1
mstream.Open
mstream.Write strImage
sFullPath = sTemporaryFolder & "/forum/logo.gif"
mstream.SaveToFile sFullPath, 2
WriteBlobToFile = sTemporaryFolder & "/forum/logo.gif"

set mStream = nothing
set rs = nothing
set cn = nothing
End function
%>


<%
dim str
str="Yes"
Dim Conn, strDSN,rsobjfea, strSQLfea
Set Conn = Server.CreateObject("ADODB.Connection")
strDSN = "Provider=SQLOLEDB.1;Password=1234;User ID=sql user;Data Source=BARBELL;Initial Catalog=OnlineStore;"
Conn.Open strDSN

Set rsobjfea = Server.CreateObject("ADODB.Recordset")
strSQLfea="select Large_Picture,Sub_Item, Description from Products_Details1 where Featured='" & str & "'"
rsobjfea.Open strSQLfea, Conn, 2,2
%>


<h1>Featured Items !</h1>
<table cellpadding="10px" >
<%
Dim sImgpath
Do while not rsobjfea.eof
sImgpath = ""

%>
<tr>
<th colspan="2"><%=rsobjfea.Fields("Sub_Item")%></th>
</tr>
<tr>

<td valign="top">
<%
Response.ContentType = "image/jpeg"
sImgpath = WriteBlobToFile(rsobjfea("Large_Picture"))
%>
<img name="ProductPhoto"
src="<%=sImgpath%>"
width="144" height="144" /></td>
<td valign="top"><%=rsobjfea.Fields("Description")%></td>
</tr>
<%
rsobjfea.MoveNext
Loop
%>
</table>
</div>

<div class="navigation">
<!--#include file="/forum/navigation.html" -->
</div>
</body>
</html>




  Re: Image issue  belord at 17:12 on Wednesday, December 15, 2004
 

Hi,

Can you explain me in detail if you dont mind

thanks,

belord

  Re: Image issue  tgreer at 17:17 on Wednesday, December 15, 2004
 

If you'll re-read my posts, you'll see I don't code ASP anymore. So I can't give exact details. Do you understand the general method I've described?


  Re: Image issue  belord at 17:18 on Wednesday, December 15, 2004
 

I just get the red X icon where the image should be.

belord

  Re: Image issue  belord at 18:13 on Wednesday, December 15, 2004
 

Hi,

I have never done the response stream thats why i didnt try it if you can help me surely i will try it

your help is greatly appreciated

belord

  Re: Image issue  tgreer at 21:00 on Wednesday, December 15, 2004
 

It looks like you're writing the image to a file. What your image-producing ASP page will have to do is

1) Set the content-type correctly for an image. For example, if you'll be producing a jpeg:

<% Response.ContentType = "image/JPEG" %>

2) Then you would write out the BLOB directly to the response stream. I think you would use Response.BinaryWrite(), passing in the variable/object that you've set equal to your image.

3) Response.end()

If this ASP page is named "/forum/myImage.html", then in your main ASP page, you would set the image tag:

<img src="/forum/myImage.html" />



<Added>

It looks like you're still trying to do this in one page. That won't work. You can only have a single content-type.

I'm saying create two pages. One page will get the image from the database, and write it out.

The second page will use the first page as an image source.










CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Re: iframe problem
•  CheckBox problem with ASP.Net DataGrid
•  FREE TV on your PC!
•  IE Iframe get stucked
•  interview problem
•  Re: dynamic crystal report generation
•  Re: IFRAME Problem: Scrollbar disappears if Resize IE window
•  need help in JAVA
•  File I/O semi-advanced question


Recent Articles
Multiple submit buttons with form validation
Understanding Hibernate ORM for Java/J2EE
HTTP screen-scraping and caching
a javascript calculator
A simple way to JTable
Java Native Interface (JNI)
Parsing Dynamic Layouts
MagicGrid
Caching With ASP.Net
Creating CSS Buttons


Site Survey
Help us serve you better. Take a five minute survey. Click here!

© Copyright codetoad.com 2001-2005