471,316 Members | 989 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,316 software developers and data experts.

Pictures on SQL Server

Hello

I'am building an web application that enable users to get data stored in a
SQL Server.

My problem is pictures. How can I display pictures stored in SQL Server - In
the old days, I took the picture and saved it into disk and loaded from
here...

Kind regards

Johnny E Jensen
Nov 19 '05 #1
4 2985
This may help (one idea)
http://www.samspublishing.com/articl...?p=377078&rl=1

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
"Johnny Emde" wrote:
Hello

I'am building an web application that enable users to get data stored in a
SQL Server.

My problem is pictures. How can I display pictures stored in SQL Server - In
the old days, I took the picture and saved it into disk and loaded from
here...

Kind regards

Johnny E Jensen

Nov 19 '05 #2
sorry for my english :-)
this example it's for access but you can convert to sql server

<script runat="server" Language="C#">
void Page_Load(Object o,EventArgs e) {
string db, strsql, idx;
idx = Request.QueryString["id"];
if (idx = =null) idx = "1";

db="immagini.mdb";
OleDbConnection myconnection = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data
Source="+Request.MapPath(db));
myconnection.Open();

strsql = "Select image,name,contenttype FROM Tabella1 where id=" + idx;
OleDbCommand mycommand = new OleDbCommand(strsql,myconnection);
OleDbDataReader re = mycommand.ExecuteReader();

if (re.Read()) {
Response.Clear();
Response.ClearContent();
Response.ContentType = re["contenttype"].ToString();
Response.BinaryWrite((byte[])re["image"]);
}
else
Response.Write ("nothing image for this ID");

re.Close();
myconnection.Close();
}
</script>
in the page:
<img src="view_image.aspx?id=1">
good luck

byez
imperugo (exCartman)
myblog : http://imperugo.blogspot.com


"Johnny Emde" <em**@emde.dk> wrote in message
news:e3**************@TK2MSFTNGP12.phx.gbl...
Hello

I'am building an web application that enable users to get data stored in a
SQL Server.

My problem is pictures. How can I display pictures stored in SQL Server -
In the old days, I took the picture and saved it into disk and loaded from
here...

Kind regards

Johnny E Jensen

Nov 19 '05 #3
You'll need a special page (or an HTTP Module that simulates a page) to
retrieve the image from SQL Server so an Image control on a page can
reference it.

These articles contain most (if not all) of the details you'll need.
http://SteveOrr.net/articles/EasyUploads.aspx
http://SteveOrr.net/articles/ImproveYourImages.aspx

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Johnny Emde" <em**@emde.dk> wrote in message
news:e3**************@TK2MSFTNGP12.phx.gbl...
Hello

I'am building an web application that enable users to get data stored in a
SQL Server.

My problem is pictures. How can I display pictures stored in SQL Server -
In the old days, I took the picture and saved it into disk and loaded from
here...

Kind regards

Johnny E Jensen

Nov 19 '05 #4
Thangs! ( that was quick reply )

Both esamples works fine - if i would have the picture shown at the current
page - I'am building a
web user control that holds a control to display picture ie. Image Control.
And its very important
that the picture are showed in that control.

Please more help - i love examples....

Kind regards
Johnny E Jensen

"imperugo" <ug**********@dgsworld.it> wrote in message
news:et**************@TK2MSFTNGP15.phx.gbl...
sorry for my english :-)
this example it's for access but you can convert to sql server

<script runat="server" Language="C#">
void Page_Load(Object o,EventArgs e) {
string db, strsql, idx;
idx = Request.QueryString["id"];
if (idx = =null) idx = "1";

db="immagini.mdb";
OleDbConnection myconnection = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data
Source="+Request.MapPath(db));
myconnection.Open();

strsql = "Select image,name,contenttype FROM Tabella1 where id=" + idx;
OleDbCommand mycommand = new OleDbCommand(strsql,myconnection);
OleDbDataReader re = mycommand.ExecuteReader();

if (re.Read()) {
Response.Clear();
Response.ClearContent();
Response.ContentType = re["contenttype"].ToString();
Response.BinaryWrite((byte[])re["image"]);
}
else
Response.Write ("nothing image for this ID");

re.Close();
myconnection.Close();
}
</script>
in the page:
<img src="view_image.aspx?id=1">
good luck

byez
imperugo (exCartman)
myblog : http://imperugo.blogspot.com


"Johnny Emde" <em**@emde.dk> wrote in message
news:e3**************@TK2MSFTNGP12.phx.gbl...
Hello

I'am building an web application that enable users to get data stored in
a SQL Server.

My problem is pictures. How can I display pictures stored in SQL Server -
In the old days, I took the picture and saved it into disk and loaded
from here...

Kind regards

Johnny E Jensen


Nov 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by JakeC | last post: by
6 posts views Thread by Nutshell | last post: by
13 posts views Thread by gooze | last post: by
9 posts views Thread by C.Joseph Drayton | last post: by
8 posts views Thread by cbmeeks | last post: by
4 posts views Thread by Zeljko Bilandzija | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.