All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
简单学习动态网页制作PHP中的Cookies_php资料_编程技术
PHP入门:什么是PHP-网站开发为什么选择PHP-_[PHP教程]
ASP.NET技巧:数据导出到Excel最为简易的方法_[Asp.Net教程]
Sql,server内存不断增加的问题分析_[SQL,Server教程]
SQLServer分页查询通用存储过程_[SQL Server教程]
.Net,Framework3.0,实践纪实之布局_[Asp.Net教程]
ASP.NET服务器控件PleaseWaitButton_[Asp.Net教程]
C#中多维数组的声明
在网页中插入媒体播放器详细参考
简述.net编程中容易出现的错误认识_[Asp.Net教程]
Reading number is top 10 pictures
这才叫绝色美女2
Born After 90 Beijing sports university campus flower photos5
鸡也看毛片
Thrilling English baby
XuRe xuan cool and refreshing photoes2
教你22句话
色狗系列
Sora aoi in China4
奇趣的世界记录2
So beauty, will let you spray blood10
Download software ranking
在线棋牌游戏3.05版
linux高级编程
Love the forty days
Tram sex maniac 2 (H) rar bag8
Unix video tutorial7
Sora aoi, the nurse, uniform ,nursing assistant
双旗镇刀客B
仙剑奇侠传98版歌曲
美女写真3
Boxer's Top ten classic battle9
delv published in(发表于) 2014/1/10 6:30:56 Edit(编辑)
图片保存到数据库和从数据库读取图片并显示_[Asp.Net教程]

图片保存到数据库和从数据库读取图片并显示_[Asp.Net教程]

图片保存到数据库和从数据库读取图片并显示_[Asp.Net教程]

public void imgToDB(string sql)
{ //参数sql中要求保存的imge变量名称为@images
//调用方法如:imgToDB("update UserPhoto set Photo=@images where UserNo='" + temp + "'");
FileStream fs = File.OpenRead(t_photo.Text);
byte[] imageb = new byte[fs.Length];
fs.Read(imageb, 0, imageb.Length);
fs.Close();
SqlCommand com3 = new SqlCommand (sql,con);
com3.Parameters.Add("@images", SqlDbType.Image).Value = imageb;
if (com3.Connection.State == ConnectionState.Closed)
com3.Connection.Open();
try
{
com3.ExecuteNonQuery();
}
catch
{ }
finally
{ com3.Connection.Close(); }
}

数据库中读出图片并显示在picturebox中:


方法一:
private void ShowImage(string sql)
{
//调用方法如:ShowImage("select Photo from UserPhoto where UserNo='" + userno +"'");
SqlCommand cmd = new SqlCommand(sql, conn);
conn.Open();
byte[] b= (byte[])cmd.ExecuteScalar();
if (b.Length 〉 0)
{
MemoryStream stream = new MemoryStream(b, true);
stream.Write(b, 0, b.Length);
pictureBox1.Image = new Bitmap(stream);
stream.Close();
}
conn.Close();
}


方法二:当在dg中选中某行时:
private void dg_MouseUp(object sender, MouseEventArgs e)
{
//整行选择
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{//用户编号,姓名,性别,身份证号,籍贯,学院,系所,校区,部门,电话,照片
//显示相片
object imgobj=dg[10, dg.CurrentRow.Index].Value;
if (imgobj != null && !Convert.IsDBNull(imgobj))
{
byte[] imgb = (byte[])imgobj;
MemoryStream memStream = new MemoryStream(imgb);
try
{
Bitmap myimge = new Bitmap(memStream);
this.pictureBox1.Image = myimge;
}
catch
{
DB.msgbox("从数据库读取相片失败!");
}
}
else
pictureBox1.Image = null;
}
}


http://www.cnblogs.com/tuyile006/archive/2007/01/08/614718.html


来源:博客园







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.