Pictures on SQL Server

J

Johnny Emde

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
 
I

imperugo

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
 
J

Johnny Emde

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 said:
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 said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top