|
|
 |
|
 |
在SQL Server中保存和输出图片 |
热 荐 ★★★ |
|
|
|
| 在SQL Server中保存和输出图片 |
|
|
| 作者:佚名 文章来源:本站整理 更新时间:2008-10-10 21:24:43 |
|
|
|
介绍
有时候我们需要保存一些binary data进数据库。SQL Server提供一个叫做image的特殊数据类型供我们保存binary data。Binary data可以是图片、文档等。在这篇文章中我们将看到如何在SQL Server中保存和输出图片。 建表 为了试验这个例子你需要一个含有数据的table(你可以在现在的库中创建它,也可以创建一个新的数据库),下面是它的结构: 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 = imgdatastrea[1] [2] [3] 下一页 更多精彩:学习网->http://www.haohao888.com.cn 网络编程->http://www.51wlpc.com 电脑设备->http://www.xpmaster.cn
|
|
|
|
| 文章录入:admin 责任编辑:admin |
|
|
上一篇文章: 优化ASP应用程序技巧四则 下一篇文章: 提高ASP页面的执行效率 |
|
|
|
|
|
|
|
|
|
|
|
|