C从SQL数据库中读取和存入图片.docVIP

  • 9
  • 0
  • 约1.62万字
  • 约 20页
  • 2016-11-26 发布于广东
  • 举报
C从SQL数据库中读取和存入图片.doc

C#从SQL 数据库中读取和存入图片本实例主要介绍如何将图片存入数据库。将图片存入数据库,首先要在数据库中建立一张表,将存储图片的字段类型设为Image类型,用FileStream类、BinaryReader把图片读成字节的形式,赋给一个字节数组,然后用ADO.SqlCommand对象的ExecuteNonQuery()方法来把数据保存到数据库中。主要代码如下: ??? private void button1_Click(object sender, EventArgs e) ??????? { ????????? openFileDialog1.Filter = *jpg|*.JPG|*.GIF|*.GIF|*.BMP|*.BMP; ??????????? if(openFileDialog1.ShowDialog()==DialogResult.OK) ??????????? { ????????????? string fullpath =openFileDialog1.FileName;//文件路径 ????????????? FileStream fs = new FileStream(fullpath, FileMode.Open); ??????????????? byte[] imagebytes =new byte[fs.Length]; ??????????

文档评论(0)

1亿VIP精品文档

相关文档