没有合适的资源?快使用搜索试试~ 我知道了~
C#中图片存入SQL数据库
4星 · 超过85%的资源 需积分: 18 41 下载量 176 浏览量
2011-06-06
17:34:51
上传
评论 2
收藏 31KB DOC 举报
温馨提示
试读
3页
C#中图片存入SQL数据库 这是我在网上找的资源,挺有用的,可以用于把C#中的图片存入数据库中,一般是照片的存储,用于做一些人员管理方面的系统,如有不当,请原谅
资源推荐
资源详情
资源评论
C#中图片存入 SQL 数据库 收藏
//将 SQL server2000 中保存的图像显示在 Picture 中
private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
byte[] buffByte = null;
string comm = @"select img from table1 where id = " + this.listBox1.SelectedValue ;
this.sqlCommand1 = new System.Data.SqlClient.SqlCommand ();
this.sqlCommand1.CommandType = System.Data.CommandType.Text ;
this.sqlCommand1.CommandText = comm;
this.sqlCommand1.Connection = this.sqlConnection1 ;
this.sqlConnection1.Open();
System.Data.SqlClient.SqlDataReader rd = this.sqlCommand1.ExecuteReader();
while (rd.Read())
{
buffByte = ((byte[])rd[0]);
}
rd.Close();
this.sqlConnection1.Close();
//将图像的字节数组放入内存流
System.IO.MemoryStream ms = new System.IO.MemoryStream(buffByte);
//通过流对象建立 Bitmap
System.Drawing.Bitmap bmp = new Bitmap(ms);
this.pictureBox1.Image = bmp;
}
//将图像保存到 SQL server2000 的 Image 字段中
private void button2_Click_1(object sender, System.EventArgs e)
{
string pathName;
if (this.openFileDialog1.ShowDialog()==System.Windows.Forms.DialogResult.OK)
{
pathName = this.openFileDialog1.FileName;
System.Drawing.Image img = System.Drawing.Image.FromFile(pathName);
this.pictureBox1.Image = img;
//将图像读入到字节数组
System.IO.FileStream fs = new
System.IO.FileStream(pathName,System.IO.FileMode.Open,System.IO.FileAccess.Read);
byte[] buffByte = new byte[fs.Length];
fs.Read(buffByte,0,(int)fs.Length);
fs.Close();
fs = null;
//建立 Command 命令
资源评论
- yang_jx2012-11-06还行,能用,不过就两个函数,2分有点多了
- lonlon292014-10-25看看吧,正好需要这方面的功能
- a3137575862013-05-19不错,长知识了
weiman2010
- 粉丝: 0
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功