注册 | 登录
收藏 | 帮助
热门文章
编辑推荐
相关文章  
简单三步走堵死SQLServer注入漏洞
黑客攻破SQL服务器系统的十种方法
透明防火墙架设的完全攻略(brid
linux定时备份mysql数据库
qmail+vpopmail+sqwebmail的安装
qmail Vpopmail And sqwebmail H
qmail Vpopmail And sqwebmail H
qmail Vpopmail And sqwebmail H
qmail Vpopmail And sqwebmail H
qmail Vpopmail And sqwebmail H
您现在的位置: 顶尖设计 >> IT学院 >> 数据库 >> MS SQL >> 文章正文
在SQL Server中保存和输出图片
作者:佚名  来源:不详  点击:  更新:2006-12-20
简介:

介绍

 

    有时候我们需要保存一些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.

 

保存imagesSQL 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

[1] [2] [3] [4] 下一页




  • 上一篇文章:
  • 下一篇文章:
  • 分享此文:该页面添加到 Mister Wong 添加到雅虎Yahoo!收藏 Add to:Del.icio.us Post to Furl Digg this 添加到Google书签 reddit spurl blogmarks 365Key 评论  收藏  分享  打印
     我来说两句
    姓名:       验证码:   
    主页: 
    评分: 1分 2分 3分 4分 5分
    本频道近期热评文章:
      关于我们 | 联系我们 | 站点地图 | 广告投放 | 友情链接 | 在线留言 | 版权申明
    版权所有 © 2004-2007 顶尖设计(bobd.cn)
    未经授权禁止转载,摘编,复制本站内容或建立镜像. 沪ICP备07504942号 
    网络110
    报警服务