问题如下:
我希望能在table的指定的td里显示出我从sql server里
取到的image类型数据,不知道有没有办法做到?
我所知道的一般在页面上显示sql server image类型数据
的方法如下:
1.从sql server中取到的image类型的数据,将其存储到
byte[]数组里面
2.设置Response.ContentType="image/gif"
3.用Response.BinaryWrite方法显示出来
但我不知道该如何指定位置。
请高人指点一下,非常感谢!
我希望能在table的指定的td里显示出我从sql server里
取到的image类型数据,不知道有没有办法做到?
我所知道的一般在页面上显示sql server image类型数据
的方法如下:
1.从sql server中取到的image类型的数据,将其存储到
byte[]数组里面
2.设置Response.ContentType="image/gif"
3.用Response.BinaryWrite方法显示出来
但我不知道该如何指定位置。
请高人指点一下,非常感谢!
Column Name
Datatype
Purpose
ID
Integer
identity column Primary key IMGTITLE
Varchar(50)
Stores some user friendly title to identity the image IMGTYPE
Varchar(50)
Stores image content type. This will be same as recognized content types of ASP.NET IMGDATA
Image
Stores actual image or binary data.
保存images进SQL Server数据库 为了保存图片到table你首先得从客户端上传它们到你的web服务器。你可以创建一个web form,用TextBox得到图片的标题,用HTML File Server Control得到图片文件。确信你设定了Form的encType属性为multipart/form-data。
Stream imgdatastream = File1.PostedFile.InputStream;
int imgdatalen = File1.PostedFile.ContentLength; string imgtype = File1.PostedFile.ContentType; string imgtitle = TextBox1.Text; byte[] imgdata = new byte[imgdatalen]; int n = imgdatastream.Read(imgdata,0,imgdatalen); string connstr= ((NameValueCollection)Context.GetConfig ("appSettings"))["connstr"]; SqlConnection connection = new SqlConnection(connstr); SqlCommand command = new SqlCommand ("INSERT INTO ImageStore(imgtitle,imgtype,imgdata) VALUES ( @imgtitle, @imgtype,@imgdata )", connection );
SqlParameter paramTitle = new SqlParameter ("@imgtitle", SqlDbType.VarChar,50 ); paramTitle.Value = imgtitle; command.Parameters.Add( paramTitle);
SqlParameter paramData = new SqlParameter ( "@imgdata", SqlDbType.Image ); paramData.Value = imgdata; command.Parameters.Add( paramData );
SqlParameter paramType = new SqlParameter ( "@imgtype", SqlDbType.VarChar,50 ); paramType.Value = imgtype; command.Parameters.Add( paramType );
connection.Open(); int numRowsAffected = command.ExecuteNonQuery(); connection.Close();
http://dotnet.aspx.cc/ShowDetail.aspx?id=2A5DD7C6-A45A-48AB-A2E8-342A29F17506
http://dotnet.aspx.cc/ShowDetail.aspx?id=ECD9AE16-8FF0-4A1C-9B9F-5E8B641CB1B1
显示的位置没发用<td>来定位,好像不管用.
试试:在<td>里放一个iframe来控制.把显示图片的页面放iframe里
show.aspx的page_load中写读图片流的代码
看看这个是怎样用C#+Sql Server存取图像的
我过一段时间在结帖,让有需要的朋友也能看看。