how to put jpg from Access into asp-page?
how to put jpg from Access into asp-page?
am 16.04.2005 22:18:52 von Ben
Hi,
In Access, i defined a field OLE ('pict')and put some jpg files in it.
I want to get them, just like the other textfield, into a asp-page.
I get no error, but my problem is that the text field appears but not the
jpg files (only a red cross).
See my code:
<%
set objdc = Server.CreateObject("ADODB.Connection")
objdc.Open("provider=Microsoft.Jet.OLEDB.4.0; Data Source =c:\test.mdb")
sql="select field1, pict from mytable..."
dim rsArray
Set rs = objdc.execute(sql)
if rs.eof then
rec=0
else
rsArray = rs.GetRows()
rec = UBound(rsArray, 2) + 1
%>
field1 |
picture |
<%
rs.MoveFirst
for i= 0 to rec-1
%>
<%=rsArray(0,i)%> |
|
<%
rs.MoveNext
next
end if
rs.close
objdc.close
set objdc=nothing
%>
Thanks
Ben
Re: how to put jpg from Access into asp-page?
am 17.04.2005 01:27:59 von Bob Lehmann
> In Access, i defined a field OLE ('pict')and put some jpg files in it.
Bad choice. You should just store the image path, and build your img src
from that instead.
Bob Lehmann
"Ben" wrote in message
news:ehAeJIsQFHA.3384@TK2MSFTNGP10.phx.gbl...
> Hi,
>
> In Access, i defined a field OLE ('pict')and put some jpg files in it.
> I want to get them, just like the other textfield, into a asp-page.
> I get no error, but my problem is that the text field appears but not the
> jpg files (only a red cross).
> See my code:
> <%
> set objdc = Server.CreateObject("ADODB.Connection")
> objdc.Open("provider=Microsoft.Jet.OLEDB.4.0; Data Source =c:\test.mdb")
> sql="select field1, pict from mytable..."
>
> dim rsArray
> Set rs = objdc.execute(sql)
> if rs.eof then
> rec=0
> else
> rsArray = rs.GetRows()
> rec = UBound(rsArray, 2) + 1
> %>
>
>
>
>
> field1 |
>
>
> picture |
>
>
> <%
> rs.MoveFirst
> for i= 0 to rec-1
> %>
>
>
>
> <%=rsArray(0,i)%> |
>
> |
>
> <%
> rs.MoveNext
> next
> end if
> rs.close
> objdc.close
> set objdc=nothing
> %>
>
>
>
> Thanks
> Ben
>
>
>
Re: how to put jpg from Access into asp-page?
am 17.04.2005 11:24:58 von Ben
thanks
"Bob Lehmann" wrote in message
news:%23XRYgvtQFHA.1172@TK2MSFTNGP12.phx.gbl...
> > In Access, i defined a field OLE ('pict')and put some jpg files in it.
> Bad choice. You should just store the image path, and build your img src
> from that instead.
>
> Bob Lehmann
>
> "Ben" wrote in message
> news:ehAeJIsQFHA.3384@TK2MSFTNGP10.phx.gbl...
> > Hi,
> >
> > In Access, i defined a field OLE ('pict')and put some jpg files in it.
> > I want to get them, just like the other textfield, into a asp-page.
> > I get no error, but my problem is that the text field appears but not
the
> > jpg files (only a red cross).
> > See my code:
> > <%
> > set objdc = Server.CreateObject("ADODB.Connection")
> > objdc.Open("provider=Microsoft.Jet.OLEDB.4.0; Data Source =c:\test.mdb")
> > sql="select field1, pict from mytable..."
> >
> > dim rsArray
> > Set rs = objdc.execute(sql)
> > if rs.eof then
> > rec=0
> > else
> > rsArray = rs.GetRows()
> > rec = UBound(rsArray, 2) + 1
> > %>
> >
> >
> >
> >
> > field1 |
> >
> >
> > picture |
> >
> >
> > <%
> > rs.MoveFirst
> > for i= 0 to rec-1
> > %>
> >
> >
> >
> > <%=rsArray(0,i)%> |
> >
> > |
> >
> > <%
> > rs.MoveNext
> > next
> > end if
> > rs.close
> > objdc.close
> > set objdc=nothing
> > %>
> >
> >
> >
> > Thanks
> > Ben
> >
> >
> >
>
>
Re: how to put jpg from Access into asp-page?
am 18.04.2005 15:16:48 von Famel Lee
The src property of img element doesn't support binary data. You cannot
assign binary data to it. There are two ways around:
1) as in another reply, keep the image file in file system and only save
links in database.
2) keep the binary data in database as you did, and write another asp to get
the binary data from database and make the src property points to this asp,
e.g.
"Ben" wrote in message
news:ehAeJIsQFHA.3384@TK2MSFTNGP10.phx.gbl...
> Hi,
>
> In Access, i defined a field OLE ('pict')and put some jpg files in it.
> I want to get them, just like the other textfield, into a asp-page.
> I get no error, but my problem is that the text field appears but not the
> jpg files (only a red cross).
> See my code:
> <%
> set objdc = Server.CreateObject("ADODB.Connection")
> objdc.Open("provider=Microsoft.Jet.OLEDB.4.0; Data Source =c:\test.mdb")
> sql="select field1, pict from mytable..."
>
> dim rsArray
> Set rs = objdc.execute(sql)
> if rs.eof then
> rec=0
> else
> rsArray = rs.GetRows()
> rec = UBound(rsArray, 2) + 1
> %>
>
>
>
>
> field1 |
>
>
> picture |
>
>
> <%
> rs.MoveFirst
> for i= 0 to rec-1
> %>
>
>
>
> <%=rsArray(0,i)%> |
>
> |
>
> <%
> rs.MoveNext
> next
> end if
> rs.close
> objdc.close
> set objdc=nothing
> %>
>
>
>
> Thanks
> Ben
>
>
>
Re: how to put jpg from Access into asp-page?
am 18.04.2005 19:47:36 von mmcginty
"Bob Lehmann" wrote in message
news:%23XRYgvtQFHA.1172@TK2MSFTNGP12.phx.gbl...
>> In Access, i defined a field OLE ('pict')and put some jpg files in it.
> Bad choice. You should just store the image path, and build your img src
> from that instead.
To me that would be an opinion, not an answer to the question. To answer
the question, the reason your ASP/HTML code doesn't work, is that IMG
elements don't accept the binary image data as their src attribute, it must
be a fully-qualified or relative URL.
If you want to write image data from a database field, you must create a
special ASP script to do only that, and then set the content type
appropriately, and then use Response.BinaryWrite to write it. Problem with
Jet is that it adds a bunch of OLE stuff to the actual image data, making it
work in Access apps, but I'm not sure how well IE (or any other browser)
will handle it.
I have code that works well with SQL server, I'll make it available if you
want to see it.
-Mark
> Bob Lehmann
>
> "Ben" wrote in message
> news:ehAeJIsQFHA.3384@TK2MSFTNGP10.phx.gbl...
>> Hi,
>>
>> In Access, i defined a field OLE ('pict')and put some jpg files in it.
>> I want to get them, just like the other textfield, into a asp-page.
>> I get no error, but my problem is that the text field appears but not the
>> jpg files (only a red cross).
>> See my code:
>> <%
>> set objdc = Server.CreateObject("ADODB.Connection")
>> objdc.Open("provider=Microsoft.Jet.OLEDB.4.0; Data Source =c:\test.mdb")
>> sql="select field1, pict from mytable..."
>>
>> dim rsArray
>> Set rs = objdc.execute(sql)
>> if rs.eof then
>> rec=0
>> else
>> rsArray = rs.GetRows()
>> rec = UBound(rsArray, 2) + 1
>> %>
>>
>>
>>
>>
>> field1 |
>>
>>
>> picture |
>>
>>
>> <%
>> rs.MoveFirst
>> for i= 0 to rec-1
>> %>
>>
>>
>>
>> <%=rsArray(0,i)%> |
>>
>> |
>>
>> <%
>> rs.MoveNext
>> next
>> end if
>> rs.close
>> objdc.close
>> set objdc=nothing
>> %>
>>
>>
>>
>> Thanks
>> Ben
>>
>>
>>
>
>
Re: how to put jpg from Access into asp-page?
am 11.05.2005 22:47:56 von Pervaiz Khawaja
still doesn't work. do you have working example. thanks
"Famel Lee" wrote in message
news:%23vNLyjBRFHA.3336@TK2MSFTNGP10.phx.gbl...
> The src property of img element doesn't support binary data. You cannot
> assign binary data to it. There are two ways around:
>
> 1) as in another reply, keep the image file in file system and only save
> links in database.
> 2) keep the binary data in database as you did, and write another asp to
get
> the binary data from database and make the src property points to this
asp,
> e.g.
>
> "Ben" wrote in message
> news:ehAeJIsQFHA.3384@TK2MSFTNGP10.phx.gbl...
> > Hi,
> >
> > In Access, i defined a field OLE ('pict')and put some jpg files in it.
> > I want to get them, just like the other textfield, into a asp-page.
> > I get no error, but my problem is that the text field appears but not
the
> > jpg files (only a red cross).
> > See my code:
> > <%
> > set objdc = Server.CreateObject("ADODB.Connection")
> > objdc.Open("provider=Microsoft.Jet.OLEDB.4.0; Data Source =c:\test.mdb")
> > sql="select field1, pict from mytable..."
> >
> > dim rsArray
> > Set rs = objdc.execute(sql)
> > if rs.eof then
> > rec=0
> > else
> > rsArray = rs.GetRows()
> > rec = UBound(rsArray, 2) + 1
> > %>
> >
> >
> >
> >
> > field1 |
> >
> >
> > picture |
> >
> >
> > <%
> > rs.MoveFirst
> > for i= 0 to rec-1
> > %>
> >
> >
> >
> > <%=rsArray(0,i)%> |
> >
> > |
> >
> > <%
> > rs.MoveNext
> > next
> > end if
> > rs.close
> > objdc.close
> > set objdc=nothing
> > %>
> >
> >
> >
> > Thanks
> > Ben
> >
> >
> >
>
Re: how to put jpg from Access into asp-page?
am 12.05.2005 05:03:24 von mmcginty
"Pervaiz Khawaja" wrote in message
news:uKDA5qmVFHA.3488@tk2msftngp13.phx.gbl...
> still doesn't work. do you have working example. thanks
This example is written in server-side jscript. It works with SQL Server 7
and 2K, whether or not it works with
Jet, I neither know nor care -- life is too short to waste it working with
Jet!
The table is very simple, it has an identity field [id], a blob field [img],
and a datetime field [obtained]. (It sends [obtained] down with the image
as it's last-updated date.)
The stored procedure is likewise very simple, it just has a select statement
in it (it's the simplest vehicle for a parameter.) How you open the
recordset is your issue, the only requirement is that you open a recordset
and position it on the row that contains the picture.
In the image tage the src would be "img.asp?id=6971" (or whatever record id
value.) You can also load it in IE by itself.
Again, as I mentioned in my first post to this thread, this may not work
with Jet, as it adds its own wrapper to bin data for Access' purposes.
-Mark
''// this comment is legal in both vbs and jscript
''// file img.asp starts here
<%@ language=jscript %>
<%
var id = Request("id").item;
if (id == null)
Response.End();
id = parseInt(id);
if (isNaN(id))
Response.End();
var cn = new ActiveXObject("ADODB.Connection");
cn.Open(cs); // conn string is defined in server-side include
var rs = new ActiveXObject("ADODB.Recordset");
cn.spGetImg(id, rs);
if (rs.EOF)
Response.End();
var d = new Date(rs("obtained").value);
Response.AddHeader("Last-Modified", d.toUTCString());
var s = new ActiveXObject("ADODB.Stream");
s.Mode = 3;
s.Type = 1;
s.Open();
Response.ContentType = "image/jpeg";
// write the contents of the blob field to the stream
s.Write(rs.Fields(0).Value);
s.Position = 0;
Response.BinaryWrite(s.Read());
// This code would be more efficient if there was a way
// to copy from the IStream exposed by a blob field,
// to the IStream exposed by the Response object.
s.Close();
rs.Close();
cn.Close();
cn = rs = s = null;
%>
''// file img.asp ends here
> "Famel Lee" wrote in message
> news:%23vNLyjBRFHA.3336@TK2MSFTNGP10.phx.gbl...
>> The src property of img element doesn't support binary data. You cannot
>> assign binary data to it. There are two ways around:
>>
>> 1) as in another reply, keep the image file in file system and only save
>> links in database.
>> 2) keep the binary data in database as you did, and write another asp to
> get
>> the binary data from database and make the src property points to this
> asp,
>> e.g.
>>
>> "Ben" wrote in message
>> news:ehAeJIsQFHA.3384@TK2MSFTNGP10.phx.gbl...
>> > Hi,
>> >
>> > In Access, i defined a field OLE ('pict')and put some jpg files in it.
>> > I want to get them, just like the other textfield, into a asp-page.
>> > I get no error, but my problem is that the text field appears but not
> the
>> > jpg files (only a red cross).
>> > See my code:
>> > <%
>> > set objdc = Server.CreateObject("ADODB.Connection")
>> > objdc.Open("provider=Microsoft.Jet.OLEDB.4.0; Data Source
>> > =c:\test.mdb")
>> > sql="select field1, pict from mytable..."
>> >
>> > dim rsArray
>> > Set rs = objdc.execute(sql)
>> > if rs.eof then
>> > rec=0
>> > else
>> > rsArray = rs.GetRows()
>> > rec = UBound(rsArray, 2) + 1
>> > %>
>> >
>> >
>> >
>> >
>> > field1 |
>> >
>> >
>> > picture |
>> >
>> >
>> > <%
>> > rs.MoveFirst
>> > for i= 0 to rec-1
>> > %>
>> >
>> >
>> >
>> > <%=rsArray(0,i)%> |
>> >
>> > |
>> >
>> > <%
>> > rs.MoveNext
>> > next
>> > end if
>> > rs.close
>> > objdc.close
>> > set objdc=nothing
>> > %>
>> >
>> >
>> >
>> > Thanks
>> > Ben
>> >
>> >
>> >
>>
>
>