jeg har et minimalistisk eksempel paa lager (lettere tilrettet):
<%@ import namespace="System.Data.SqlClient" %>
<script language="C#" runat="server">
private const string URLPREFIX = "
http://localhost/getdb2.aspx?id=";void Page_Load(Object sender, EventArgs e)
{
string id = Request["id"];
pic.Src = URLPREFIX + id;
}
</script>
<img id="pic" runat="server"/>
og
<%@ import namespace="System.Data" %>
<%@ import namespace="System.Data.SqlClient" %>
<script language="C#" runat="server">
private const string CONNSTR = "Server=ARNEPC3;Integrated Security=SSPI;Database=Test";
void Page_Load(Object sender, EventArgs e)
{
string id = Request["id"];
/**/
SqlConnection con = new SqlConnection(CONNSTR);
con.Open();
SqlCommand sel = new SqlCommand("SELECT pic FROM od WHERE id = " + id, con);
byte[] b = (byte[])sel.ExecuteScalar();
con.Close();
/**/
/*
byte[] b = (byte[])Cache.Get(id);
if(b == null)
{
SqlConnection con = new SqlConnection(CONNSTR);
con.Open();
SqlCommand sel = new SqlCommand("SELECT pic FROM od WHERE id = " + id, con);
b = (byte[])sel.ExecuteScalar();
con.Close();
Cache.Insert(id, b);
}
*/
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=\"" + id + ".pic\"");
Response.BinaryWrite(b);
}
</script>