c#winform读取oracle中blob字段的图片并且显示到picturebox里保存进库

上传人:xiao****1972 文档编号:84136307 上传时间:2019-03-02 格式:DOC 页数:6 大小:118.85KB
返回 下载 相关 举报
c#winform读取oracle中blob字段的图片并且显示到picturebox里保存进库_第1页
第1页 / 共6页
c#winform读取oracle中blob字段的图片并且显示到picturebox里保存进库_第2页
第2页 / 共6页
c#winform读取oracle中blob字段的图片并且显示到picturebox里保存进库_第3页
第3页 / 共6页
c#winform读取oracle中blob字段的图片并且显示到picturebox里保存进库_第4页
第4页 / 共6页
c#winform读取oracle中blob字段的图片并且显示到picturebox里保存进库_第5页
第5页 / 共6页
点击查看更多>>
资源描述

《c#winform读取oracle中blob字段的图片并且显示到picturebox里保存进库》由会员分享,可在线阅读,更多相关《c#winform读取oracle中blob字段的图片并且显示到picturebox里保存进库(6页珍藏版)》请在金锄头文库上搜索。

1、1. privatevoidbutton2_Click(objectsender,EventArgse) 2. 3. OracleConnectionconn=dbc.getConnection();/获得conn连接 4. try5. 6. conn.Open(); 7. OracleCommandcmd=conn.CreateCommand(); 8. cmd.CommandText=SELECTzpFROMkk.kkbjWHERExh=2345;/查询获得图片流 9. 10. OracleDataReaderreader=cmd.ExecuteReader();/创建一个OracleDa

2、teReader对象 11. reader.Read(); 12. 13. MemoryStreamms=newMemoryStream(byte)readerzp); 14. 15. Imageimage=Image.FromStream(ms,true); 16. 17. reader.Close(); 18. conn.Close(); 19. 20. pictureBox1.Image=image; 21. 22. catch(Exceptionee) 23. 24. MessageBox.Show(ee.Message.ToString(); 25. 26. 27. private

3、void button2_Click(object sender, EventArgs e)OracleConnection conn = dbc.getConnection();/获得conn连接tryconn.Open();OracleCommand cmd = conn.CreateCommand();cmd.CommandText = SELECT zp FROM kk.kkbj WHERE xh = 2345 ;/查询获得图片流OracleDataReader reader = cmd.ExecuteReader();/创建一个OracleDateReader对象 reader.Re

4、ad();MemoryStream ms = new MemoryStream(byte)readerzp);Image image = Image.FromStream(ms, true);reader.Close();conn.Close();pictureBox1.Image = image;catch (Exception ee)MessageBox.Show(ee.Message.ToString();-下边是上传和存入数据库有和winform(转)- 本文总结如何在.Net Winform和.Net webform()中将图片存入sqlserver中并读取显示的方法 1,使用将图片

5、上传并存入SqlServer中,然后从SqlServer中读取并显示出来 一,上传并存入SqlServer 数据库结构 create table test id identity(1,1), FImage image 相关的存储过程 Create proc UpdateImage ( UpdateImage Image ) As Insert Into test(FImage) values(UpdateImage) GO 在UpPhoto.aspx文件中添加如下: C#代码 1. 2. 然后在后置代码文件UpPhoto.aspx.cs添加btnAdd按钮的单击事件处理代码: C#代码 1.

6、privatevoidbtnAdd_Click(objectsender,System.EventArgse) 2. 3. /获得图象并把图象转换为byte 4. HttpPostedFileupPhoto=UpPhoto.PostedFile; 5. intupPhotoLength=upPhoto.ContentLength; 6. bytePhotoArray=newByteupPhotoLength; 7. StreamPhotoStream=upPhoto.InputStream; 8. PhotoStream.Read(PhotoArray,0,upPhotoLength); 9.

7、 10. /连接数据库 11. SqlConnectionconn=newSqlConnection(); 12. conn.ConnectionString=DataSource=localhost;Database=test;UserId=sa;Pwd=sa; 13. 14. SqlCommandcmd=newSqlCommand(UpdateImage,conn); 15. cmd.CommandType=CommandType.StoredProcedure; 16. 17. cmd.Parameters.Add(UpdateImage,SqlDbType.Image); 18. cm

8、d.ParametersUpdateImage.Value=PhotoArray; 19. 20. /如果你希望不使用存储过程来添加图片把上面四句代码改为: 21. /stringstrSql=Insertintotest(FImage)values(FImage); 22. /SqlCommandcmd=newSqlCommand(strSql,conn); 23. /cmd.Parameters.Add(FImage,SqlDbType.Image); 24. /cmd.ParametersFImage.Value=PhotoArray; 25. 26. conn.Open(); 27.

9、cmd.ExecuteNonQuery(); 28. conn.Close(); 29. private void btnAdd_Click(object sender, System.EventArgs e) /获得图象并把图象转换为byte HttpPostedFile upPhoto=UpPhoto.PostedFile; int upPhotoLength=upPhoto.ContentLength; byte PhotoArray=new ByteupPhotoLength; Stream PhotoStream=upPhoto.InputStream; PhotoStream.Re

10、ad(PhotoArray,0,upPhotoLength); /连接数据库 SqlConnection conn=new SqlConnection(); conn.ConnectionString=Data Source=localhost;Database=test;User Id=sa;Pwd=sa; SqlCommand cmd=new SqlCommand(UpdateImage,conn); cmd.CommandType=CommandType.StoredProcedure; cmd.Parameters.Add(UpdateImage,SqlDbType.Image); c

11、md.ParametersUpdateImage.Value=PhotoArray; /如果你希望不使用存储过程来添加图片把上面四句代码改为: /string strSql=Insert into test(FImage) values(FImage); /SqlCommand cmd=new SqlCommand(strSql,conn); /cmd.Parameters.Add(FImage,SqlDbType.Image); /cmd.ParametersFImage.Value=PhotoArray;conn.Open();cmd.ExecuteNonQuery();conn.Close(); 二,从SqlServer中读取并显示出来 在需要显示图片的地方添加如下代码: C#代码 1. ShowPhoto.aspx主体代码: C#代码 1. privatevoidPage_Load(objectsender,Sy

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 大杂烩/其它

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号