当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > asp.net 图片的读写入库实现代码

ASP.NET
AspectSharp中的代理对象
关于“使用xmlspy编写xsl文件时候,在xsl解释xml文件的时候总是使用utf-16编码”的...
如何获取本机IP?
演练:在Excel中建立自定义菜单项
Microsoft.UI.WebControl.TreeView控件的扩充使用
C#中控制流程
如何通过.Net Compact Framework来获得应用程序的当前路径
用C#快速往Excel写数据
恼人的OleDb Bug
OpenAsTextStream 方法
Visual Studio 2005 Express Beta Products所有的完整安装包。
动态下拉菜单的简单实现
如何调用他人提供的Web Service
VB6实现在Win2000/XP上隐藏进程
CSharp读写SQL Server数据库中的Image列
OA架构设计之启示
VB6使用API下载文件
激活程序的disabled的按钮
定时检测邮件并且自动转发的例子
使程序在Windows任务管理器隐藏

ASP.NET 中的 asp.net 图片的读写入库实现代码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-10   浏览: 70 ::
收藏到网摘: n/a

asp.net对图片的读写,实现将图片保存到数据库中,然后再读取显示的实现代码。 写图片c:\1.jpg到表cinfo中
复制代码 代码如下:

private static void AddCinfo()
{
string strSql = "insert into cinfo (srvtitle,csttitle,introduction,logo) values
(@srvtitle,@csttitle,@introduction,@logo)";
SqlParameter[] parms =
{
new SqlParameter("@srvtitle",SqlDbType.VarChar,30),
new SqlParameter("@csttitle",SqlDbType.VarChar,30),
new SqlParameter("@introduction",SqlDbType.NVarChar,500),
new SqlParameter("@logo",SqlDbType.Image)
};
parms[0].Value = "旅业互动";
parms[1].Value = "lyhd";
parms[2].Value = "简介";
string filePath = @"c:\1.jpg";
FileStream fs = File.OpenRead(filePath);
byte[] content = new byte[fs.Length];
fs.Read(content, 0, content.Length);
fs.Close();
parms[3].Value = content;
DBHelper.ExecuteNonQuery(CommandType.Text, strSql, parms);
}

读取图片的页面 test.aspx
复制代码 代码如下:

protected void Page_Load(object sender, EventArgs e)
{
string strSql = "select * from cinfo where id=1";
SqlDataReader reader=DBHelper.ExecuteReader(CommandType.Text, strSql, null);
if(reader.Read())
{
byte[] c=(byte[])reader["logo"];
Response.BinaryWrite(c);
}
}

用来显示图片的页面 test2.aspx
复制代码 代码如下:

<img src="test.aspx" />