sqlserver数据库中存图片
来源:互联网 发布:口红推荐 知乎 编辑:程序博客网 时间:2024/04/27 11:58
为了能存储到表中,你首先要上传它们到你的WEB 服务器上,你可以开发一个web form,它用来将客户端中TextBox web control中的图片入到你的WEB服务器上来。将你的 encType 属性设置为:myltipart/formdata.
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();
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();
- sqlserver数据库中存图片
- 如何将图片存到数据库中?
- 如何往数据库中存图片
- 如何存图片到数据库中
- C# 在SQLSERVER数据库中存取图片
- C# 在SQLSERVER数据库中存取图片
- SQLServer数据库中插入、读取图片
- 在PB中存图片入数据库及显示图片
- 图片二进制存数据库
- 数据库 存图片
- 将图片存至数据库中以及图取到PicutreBox中
- VB.NET Winform 中保存图片到数据库中
- asp中读取数据库中保存的图片存入硬盘
- 在webform中把图片存到数据库
- 在SQLServer中保存和输出图片
- 利用jxl包从sqlserver数据库中读取数据存到Excel中
- 大内存SQLServer数据库的加速剂
- 把图片存数据库(GridView)
- 在eclipse中开发struts项目的插件配置
- 关于23种设计模式的有趣见解
- 四不一坚持
- 制作可执行的JAR文件包及jar命令详解
- 遇上你是我的缘
- sqlserver数据库中存图片
- 青春有梦,勇敢去追……
- HQL查询返回的结果绑定到DataGrid的问题
- 快速排序C语言实现
- 关于控制反转IoC--Inversion of Control Containers and the Dependency Injection pattern
- 文件的加锁解锁
- 转:Virtual Earth and AJAX--Part one
- DES加密算法详解
- Windows下JAVA环境变量的设置详解