Hellow,

I am new in ASP and I have created a database in ms-access contains the fields - ID, name, designaton, photo and I uploaded all the datas. The images are in BMP. When I retrive the data by using ASP seach menthod, the id, name and designation only displayed. The photo is not displayed. In this connection, I would like to how to display images from ms-access through asp.

Kindly help me in this regard.

Senthil

Recommended Answers

All 10 Replies

Can u provide the code that u are using

Can u provide the code that u are using

Thanks !

The code is

<% = RS("Photo") %>

I recommend you to use Ole DB field in the db for the photo and retrive the image something like:

picture.asp file

<!--#include file="db.asp"-->
<%
Response.Buffer = True

' Get key
key = Request.QueryString("key")
If key = "" Or IsNull(key) Then
	Response.Redirect "picturelist.asp"
	Response.End
End If

' Open Connection to the database
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open xDb_Conn_Str
tkey = "" & key & ""
strsql = "SELECT * FROM [photos] WHERE [ID]=" & tkey
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open strsql, conn
If Not rs.Eof Then

	'rs.MoveFirst
	Response.BinaryWrite rs("Photo")
End If
rs.Close
Set rs = nothing
%>

yourpage.asp

<!--#include file="db.asp"-->
<img src="picture.asp?key=<%= jrs("id") %>" width="80" height="53" border=0 style="border: 1px solid #000000">

db.asp

<% 
xDb_Conn_Str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.mappath("../db/data.mdb") & ";"
%>

This should work

Or easier you could just use ><img src="<% = RS("Photo") %>">
But i'm not sure with BMP i prefer Jpeg or gif .. BMP are to bif for web...

Or easier you could just use ><img src="<% = RS("Photo") %>">
But i'm not sure with BMP i prefer Jpeg or gif .. BMP are to bif for web...

Thank you ! for your message.

Again the code is not working.

Actually my code is

//////////////////////////////////////////////////////
<%
dim details
details = Request.QueryString("details")
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("/asp/Faculty.mdb"))
set rs = Server.CreateObject("ADODB.recordset")
sql = "SELECT * FROM staff WHERE Token_no= '" & details & "' "

rs.Open sql, conn

do until rs.EOF

%>

</p>
<table width="954" border="1" align="center" bordercolor="#99FFFF">
<tr>
<td colspan="5"><div align="center" class="style1 style2 style7">Staff Details </div></td>
</tr>
<tr>
<td>&nbsp;</td>
<td colspan="2">
<img src="<%=rs("photo")%>" />
<td><div align="right" class="style8">Token No.: </div></td>
<td><% = RS("Token_no") %>
</td>
</tr>
<tr>
<td width="257">
<div align="right" class="style8">Name : </div></td>
<td colspan="4"><% = RS("Name") %></td>
</tr>
<tr>
<td><div align="right" class="style8">Designationa : </div></td>
<td colspan="4"><% = RS("designation") %></td>
</tr>
<tr>
<td><div align="right" class="style8">Department Name : </div></td>
<td colspan="4"><% = RS("department") %></td>
</tr>
<tr>
<td><div align="right" class="style8">Sex : </div></td>
<td colspan="4"><% = RS("sex") %></td>
</tr>
<tr>
<td><div align="right" class="style8">Date of Birth : </div></td>
<td colspan="4"><% = RS("Date_birth") %></td>
</tr>
<tr>
<td colspan="5"><span class="style37">Contact Details </span></td>
</tr>
<tr>
<td><div align="right" class="style8">Present address : </div></td>
<td colspan="4"><% = RS("Present_address") %></td>
</tr>
<tr>
<td><div align="right" class="style8">Permanent address : </div></td>
<td colspan="4"><% = RS("Permanent_address") %></td>
</tr>
<tr>
<td><div align="right" class="style8">Phone : </div></td>
<td colspan="4"><% = RS("Phone") %></td>
</tr>
<tr>
<td><div align="right" class="style8">Mobile : </div></td>
<td colspan="4"><% = RS("Mobile") %></td>
</tr>
<tr>
<td><div align="right" class="style8">Email Id : </div></td>
<td colspan="4"><% = RS("Email_ID") %></td>
</tr>
<tr>
<td><div align="right" class="style8">Qualification : </div></td>
<td colspan="4"><% = RS("Qualification") %>
;</td>
</tr>
<tr>
<td><div align="right" class="style8">Specialisations : </div></td>
<td colspan="4"><% = RS("Specializations") %></td>
</tr>
<tr>
<td><div align="right" class="style8">Experience : </div></td>
<td colspan="2"><div align="center" class="style41">Teaching</div></td>
<td colspan="2"><div align="center" class="style41">Research</div></td>
</tr>
<tr>
<td>&nbsp;</td>
<td colspan="2"><div align="center">
<% = RS("Exp_Tech") %>
</div></td>
<td colspan="2"><div align="center">
<% = RS("Exp_Res") %>
</div></td>
</tr>
<tr>
<td><div align="right" class="style8">Research Guidance : </div></td>
<td colspan="2"><div align="center" class="style41">Program</div></td>
<td width="207"><div align="center" class="style41">Awarded</div></td>
<td width="185"><div align="center" class="style41">Guidance </div></td>
</tr>
<tr>
<td><span class="style9"></span></td>
<td colspan="2"><div align="center" class="style42">M.Phil</div></td>
<td><div align="center">
<% = RS("Mphil_awarded") %>
</div></td>
<td><div align="center">
<% = RS("Mphil_guidance") %>
</div></td>
</tr>
<tr>
<td><span class="style9"></span></td>
<td colspan="2"><div align="center" class="style42">Ph.D.</div></td>
<td><div align="center">
<% = RS("Phd_awarded") %>
</div></td>
<td><div align="center">
<% = RS("Phd_guidance") %>
</div></td>
</tr>
<tr>
<td><div align="right" class="style8">Publications : </div></td>
<td colspan="2"><div align="center" class="style41">National</div></td>
<td><div align="center" class="style41">International</div></td>
<td><div align="center" class="style41">Popular article </div></td>
</tr>
<tr>
<td><span class="style9"></span></td>
<td colspan="2"><div align="center">
<% = RS("Pub_nat") %>
</div></td>
<td><div align="center">
<% = RS("Pub_int") %>
</div></td>
<td><div align="center">
<% = RS("Pub_pop") %>
</div></td>
</tr>
<tr>
<td><div align="right" class="style8">Research Projects : </div></td>
<td>&nbsp;</td>
<td><div align="center" class="style41">Minor</div></td>
<td><div align="center" class="style41">Major</div></td>
<td><div align="center" class="style41">Amount (Rs.) </div></td>
</tr>
<tr>
<td>&nbsp;</td>
<td width="135"><div align="center" class="style41">Completed</div></td>
<td width="136"><div align="center">
<% = RS("Res_pro_comp_minor") %>
</div></td>
<td><div align="center">
<% = RS("Res_pro_comp_major") %>
</div></td>
<td><div align="center">
<% = RS("Res_pro_comp_amt") %>
</div></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><div align="center" class="style41">On going </div></td>
<td><div align="center">
<% = RS("Res_pro_ongoing_minor") %>
</div></td>
<td><div align="center">
<% = RS("Res_pro_ongoing_major") %>
</div></td>
<td><div align="center">
<% = RS("Res_pro_ongoing_amt") %>
</div></td>
</tr>
<tr>
<td><div align="right" class="style8">Conference attended : </div></td>
<td colspan="2"><div align="center" class="style10">National</div></td>
<td colspan="2"><div align="center" class="style10">International</div></td>
</tr>
<tr>
<td><span class="style9"></span></td>
<td colspan="2"><div align="center">
<% = RS("Conf_attended_nat") %>
</div></td>
<td colspan="2"><div align="center">
<% = RS("Conf_attended_int") %>
</div></td>
</tr>
<tr>
<td><div align="right" class="style8">Seminar / Symposia / Workshop : </div></td>
<td colspan="2"><div align="center" class="style41">Seminar</div>
<div align="center" class="style41"></div></td>
<td><span class="style41">Symposia</span></td>
<td><div align="center" class="style41">Workshop</div></td>
</tr>
<tr>
<td><span class="style9"></span></td>
<td><div align="center">
<% = RS("Seminar") %>
</div></td>
<td colspan="2"><div align="center">
<% = RS("Symposia") %>
</div></td>
<td><div align="center">
<% = RS("Workshop") %>
</div></td>
</tr>
<tr>
<td><div align="right" class="style8">National / International </div></td>
<td colspan="4" rowspan="3"><% = RS("Award") %></td>
</tr>
<tr>
<td><div align="right" class="style8">Recognition as </div></td>
</tr>
<tr>
<td><div align="right" class="style8">award / Fellowship :</div></td>
</tr>
<tr>
<td>&nbsp;</td>
<td colspan="4">&nbsp;</td>
</tr>
</table>
<p align="center" class="style8">Back</p>
<p align="left">
<%
rs.MoveNext
loop
rs.close
conn.Close
%>
*******************************************************

the value of the "details" is passing through url

our database "photo" is the field and type is OLEDB. The image stored in the database is jpg and it shows 'package'

The results of the code ...

it display all the fields exect images.

So kindly help me to get the image.

Senthil

sorry i was out these days .. please contact me to acidu9 yahoo messenger and i will get this done for you ...
Then we will post here too the solution ok?
Have a nice day

Hi,
I would recommend you to create a pure .asp page which shows you the OLEDB data from the database only. OLEDB Data have to be responded differently than other data. Then you include that file in your results.

Create show_pic.asp, make it only show the picture from the database. You can send the ID of the database row through QueryString. In show_pic.asp you can get the data as following:

set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("/asp/Faculty.mdb"))
set rs = conn.execute("SELECT PICTURE FROM staff WHERE ID= '" & Request.QueryString("ID") & "' "
Response.binarywrite(rs(0))

Please remember to tell the browser the size of the file (in the header using Response.AddHeader), otherwise the rest of the page will not be displayed correctly.

Now, in your main page you can include show_pic.asp?id=<%=rs("id")%>.

Some modification is certainly necessary for the code to work.

Good luck!

Oh, I always said include. Please do not use include, but the src of the image.

Good luck!

Try to upload this on your server:
Picture.asp

<%
Response.Buffer = True

' Get key
key = Request.QueryString("details")
If key = "" Or IsNull(key) Then
	Response.write("error no such Id ")
	Response.End
End If

xDb_Conn_Str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.mappath("/asp/Faculty.mdb") & ";"

' Open Connection to the database
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open xDb_Conn_Str
tkey = "" & key & ""
strsql = "SELECT * FROM [photos] WHERE [ID]=" & tkey
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open strsql, conn
If Not rs.Eof Then

	'rs.MoveFirst
	Response.BinaryWrite rs("Photo")
End If
rs.Close
Set rs = nothing
%>

Run this like: http://domain/picture.asp?details=3 (Your photo ID)

If this will work then

your code will be something like:

Change the <img src<%=picture%>> with this:
<img src="picture.asp?key=<%= details %>" width="80" height="53" border=0 style="border: 1px solid #000000">

If still doesn't work contact me via yahoo mess...

Teodor

Hi,
I would recommend you to create a pure .asp page which shows you the OLEDB data from the database only. OLEDB Data have to be responded differently than other data. Then you include that file in your results.

Create show_pic.asp, make it only show the picture from the database. You can send the ID of the database row through QueryString. In show_pic.asp you can get the data as following:

set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("/asp/Faculty.mdb"))
set rs = conn.execute("SELECT PICTURE FROM staff WHERE ID= '" & Request.QueryString("ID") & "' "
Response.binarywrite(rs(0))

Please remember to tell the browser the size of the file (in the header using Response.AddHeader), otherwise the rest of the page will not be displayed correctly.

Now, in your main page you can include show_pic.asp?id=<%=rs("id")%>.

Some modification is certainly necessary for the code to work.

Good luck!

---------------------

Onceagain sorry for the disturbance,

how can I add response.addheader(name,value)
because my access file name is "Faculty", table name is "staff" and the size of 13,693 kb
whether I include "staff or faculty".

The error message shows "error no such id"

kindly help me.

Senthil

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.