保存路径到数据库
或保存二进制到到Image字段
using(SqlConnection conn=new SqlConnection(ConnectString))
{
conn.Open();
string strsql = "select photo from testimage where id=" + Request.QueryString["id"];
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = strsql;
SqlDataReader rd = cmd.ExecuteReader();
byte[] data = null;
if (rd.Read())
{
Response.Clear();
data = (byte[])rd["photo"];
Response.BinaryWrite(data);
Response.End();
}
}
Stream ImageStream;
string Path = FileUpload1.PostedFile.FileName;
int Size = FileUpload1.PostedFile.ContentLength;
string Type = FileUpload1.PostedFile.ContentType;
ImageStream = FileUpload1.PostedFile.InputStream;
byte[] Content = new byte[Size];
int Status = ImageStream.Read(Content, 0, Size);
SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
SqlCommand comm = new SqlCommand("insert into testimage(name,photo,Path,Type)values(@Name,@photo,@Path,@Type)", conn);