asp.net FileUpload 控件上传文件 以二进制的形式存入数据库并将图片显示出来
图片上传事件代码如下所示:
byte[] binary = upload.FileBytes;
StringBuilder sqlStrSb = new StringBuilder();
sqlStrSb.Append("update info set Thumb=?Imgwhere Id=200");
string mySqlConStr = "Host=localhost; uid=root; pwd=123; DataBase=db";
MySqlConnection mySqlCon = new MySqlConnection(mySqlConStr);
mySqlCon.Open();
MySqlCommand mySqlCom = new MySqlCommand();
mySqlCom.CommandText = sqlStrSb.ToString();
mySqlCom.Connection = mySqlCon;
MySqlParameter par = new MySqlParameter("?Img", MySqlDbType.VarBinary);
par.Value = binary;
mySqlCom.Parameters.Add(par);
int afn = mySqlCom.ExecuteNonQuery();
mySqlCon.Close();
注:转为二进制存入数据库的时候必须使用 MySqlDbType.VarBinary 或者 MySqlDbType.Binary 进行数据类型的限定。
图片显示代码如下所示:
string mySqlConStr = "Host=host;uid=root;pwd=123;DataBase=db;";
string sqlStr = "select ThumbData from info where Id=200;";
MySqlConnection mySqlCon = new MySqlConnection(mySqlConStr);
mySqlCon.Open();
MySqlCommand mySqlComd = new MySqlCommand();
mySqlComd.CommandText = sqlStr;
mySqlComd.Connection = mySqlCon;
MySqlDataAdapter mySqlSda = new MySqlDataAdapter();
mySqlSda.SelectCommand = mySqlComd;
DataSet ds = new DataSet();
mySqlSda.Fill(ds);
if (ds.Tables.Count > )
{
byte[] dataByte = (byte[])ds.Tables[].Rows[][];
Response.BinaryWrite(dataByte);
Response.Flush();
Response.End();
}
mySqlCon.Close();
页面显示部分:
<img src="ShowImage.aspx" />
asp.net FileUpload 控件上传文件 以二进制的形式存入数据库并将图片显示出来的更多相关文章
- .net简单的fileupload控件上传
前台代码: <asp:FileUpload ID="FileUpload1" runat="server" /> <asp:Button ID ...
- MVC项目使用easyui的filebox控件上传文件
开发环境:WIN10+IE11,浏览器请使用IE10或以上版本 开发技术框架MVC4+JQuery Easyui+knockoutjs 效果为弹出小窗体,如下图 1.前端cshtml文件代码(只包含文 ...
- c#上传文件(一)使用 .net 控件上传文件
1.html代码: <body> <form id="form1" runat="server"> <div> <as ...
- fileupload控件上传、文件下载
常遇到上传下载的功能,这里把我习惯的用法写下来: 上传: string fileName = "";fileName = this.fu_pic.FileName;if (stri ...
- python3、selenium、autoit3,通过flash控件上传文件
autoit.au3 #include <Constants.au3> WinWait(); //暂停执行脚本,直到上传对话框出现 WinActive("打开") Wi ...
- WebForm使用FileUpload控件上传压缩二进制图片
fuImage 是FileUpload页面控件 ImageHelper.CompressionImage(fuImage.FileBytes, quality); /// <summary> ...
- asp:FileUpload 控件上传多文件
<asp:FileUpload runat="server" ID="imgUpload" AllowMultiple="true" ...
- 在Update Panel 控件里面添加 File Upload 控件 上传文件
Detail Information:http://www.codeproject.com/Articles/482800/FileplusUploadplusinplusUpdateplusPane ...
- SQL语句中如何把文件以二进制数组形式存入数据库
System.IO.FileStream fs = new FileStream("1.txt", FileMode.Open); string strConn = "D ...
随机推荐
- C#邮件发送(最坑爹的邮箱-QQ邮箱)---转发(SmallFlyElephant)
C#邮件发送(最坑爹的邮箱-QQ邮箱) 最近工作挺清闲的,有空的时候陪妹子出去玩玩,自己看看小说,看看电影,日子过的挺欢乐的,这个星期幡然悔悟,代码才是我的最爱,做点小东西,就写个邮件发送程序.说的邮 ...
- php 之 文件操作(0524)
php中文件包含两种:文件,文件夹.文件夹又称目录 新建一个文件aa.txt和一个文件夹text,text文件夹下又包含bb.txt 一.判断文件类型filetype("./aa.txt&q ...
- twemproxy 安装
twemproxy 安装 1. 获取安装包 shell> wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz shell> ...
- 内核参数优化之1 keepalive解析
以下信息纯属虚构,切勿相信! tcp/ip协议中有一个keep-alive机制,即检查空连接的时效性,当一个空连接持续一段时间后,就会发送一个keep-alive探测包,来探测客户端是否还存在. 如果 ...
- WCF-基本知识
WCF-基本知识 (1)WCF服务元数据交换方式介绍: WCF服务有两种方案可以发布自己的元数据.一种是基于HTTP-GET协议提供元数据:另一种则为MEX终结点元数据交换方式,和WCF服务一样使用一 ...
- 如何修改Qt标准对话框的文字(例如,英文改成中文)
此篇文章参考qtcn论坛整理而成,因为文字和图片是本人亲自组织,所以仍算原创. http://www.qtcn.org/bbs/read-htm-tid-30650.html http://blog. ...
- Linux企业级项目实践之网络爬虫(16)——使用base64传输二进制数据
用http传输二进制的数据时,需要将二进制做一下转化,例如传输的int类型,将int类型之间转为char以后,丢失掉了长度的信息,如数字123456,本来只有4个字节,但是转化成文本的"12 ...
- Computer Graphics Thinking–texture tiling
Here is one question: how to tile texture? One thing worth to notice: The DirectX and OpenGL stipula ...
- 支持多文件上传,预览,拖拽,基于bootstra的上传插件fileinput 的ajax异步上传
首先需要导入一些js和css文件 <link href="__PUBLIC__/CSS/bootstrap.css" rel="stylesheet"&g ...
- USB枚举详细过程剖析(转)
USB枚举详细过程剖析(转) 原文地址:http://blog.163.com/luge_arm/blog/static/6774972620071018117290/ 从驱动开发网看到一篇<U ...