The original Published time: 2008-08-10--from my Baidu article [imported by moving tools]
Using System;
Using System.Data;
Using System.Configuration;
Using System.Collections;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Web.UI.HtmlControls;
Using System.Data.SqlClient;
public partial class Default4:System.Web.UI.Page
{
SqlConnection conn = new SqlConnection (configurationmanager.connectionstrings["Imgdataconn"]. ConnectionString);
protected void Page_Load (object sender, EventArgs e)
{
}
protected void Button1_Click (object sender, EventArgs e)
{
Guid gid = Guid.NewGuid ();
Conn. Open ();
SqlCommand cmd = new SqlCommand ("Insert into Imgdata (gid,filedata) VALUES (@gid, @filedata) ", conn);
cmd. Parameters.Add ("@gid", Sqldbtype.uniqueidentifier). Value = GID;
cmd. Parameters.Add ("@filedata", Sqldbtype.image). Value=fileupload1.filebytes;
cmd. ExecuteNonQuery ();
Conn. Close ();
session["GID"]=gid;
}
protected void button2_click (object sender, EventArgs e)
{
Conn. Open ();
SqlCommand cmd = new SqlCommand ("Select Filedata from Imgdata where gid= '" + session["gid"]. ToString () + "'", conn);
Byte[] FBT = (byte[]) cmd. ExecuteScalar ();
Conn. Close ();
Response.OutputStream.Write (FBT, 0, FBT. Length);
Response.End ();
}
}
Net9: Image file converted to binary stream into SQL database and read binary stream output file from database