如何把图片存入数据库
如何把图片存入数据库
取出来又怎样实现
[解决办法]
写
int imglenth = fileup.PostedFile.ContentLength;
byte[] imgdata = new byte[imglenth];
Stream steamobject = fileup.PostedFile.InputStream;
steamobject.Read(imgdata, 0, imglenth);
SqlConnection con = new SqlConnection( "server=(local);database=test;uid=sa;pwd=; ");
string add = "insert into [image1](imgdata) values (@imgdata) ";
SqlCommand cmd = new SqlCommand(add, con);
cmd.Parameters.Add( "@imgdata ", SqlDbType.Image);
cmd.Parameters[ "@imgdata "].Value = imgdata;
con.Open();
cmd.ExecuteNonQuery();
读
cmd.CommandText= 'select Image from UpImage where ID= ' '+this.Request[ 'ImageID ']+ ' ' ';
cmd.Connection=cn;
cn.Open();
SqlDataReader dr=cmd.ExecuteReader();
while(dr.Read())
{
this.Response.BinaryWrite((byte[])dr[ 'Image ']);
}