加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

wpf 图片上传(转)

发布时间:2020-12-12 12:50:30 所属栏目:百科 来源:网络整理
导读:using System.IO;using Microsoft.Win32;using Oracle.DataAccess.Client; private void Button_Upload_Click(object sender,RoutedEventArgs e) { Stream ms; byte[] picByte; OpenFileDialog openFileDialog = new OpenFileDialog { Filter = "图像文件|*.

using System.IO;using Microsoft.Win32;using Oracle.DataAccess.Client; private void Button_Upload_Click(object sender,RoutedEventArgs e) { Stream ms; byte[] picByte; OpenFileDialog openFileDialog = new OpenFileDialog { Filter = "图像文件|*.jpg;*.png;*.jpeg;*.bmp;*.gif|所有文件|*.*" }; openFileDialog.InitialDirectory = @"C:UsersAdministratorDesktop";//文件选择的默认路径 if ((bool)openFileDialog.ShowDialog()) { if ((ms = openFileDialog.OpenFile()) != null) { picByte = new byte[ms.Length]; ms.Position = 0; ms.Read(picByte,Convert.ToInt32(ms.Length)); string updateString = "UPDATE BDCFJ.T_PZ T SET ZP =:照片 WHERE BSM = ‘" + Label_Bsm.Content + "‘"; OracleCommand oraCmd = new OracleCommand(updateString,Connection.oraConn); oraCmd.Parameters.Add(new OracleParameter("照片",OracleDbType.Blob)); oraCmd.Parameters["照片"].Value = picByte; Connection.oraConn.Open(); try { int result = oraCmd.ExecuteNonQuery(); if (result < 1) { MessageBox.Show("上传照片失败,请重新上传!","提示"); } else { MessageBox.Show("成功上传照片!"); Image_New.Source = new BitmapImage(new Uri(openFileDialog.FileName)); } } catch (Exception ee) { MessageBox.Show("抱歉,出现错误:n" + ee.ToString(),"提示"); } finally { Connection.oraConn.Close(); ms.Close(); } } } else { return; } }--------------------- 作者:lizhengru2011 来源:CSDN 原文:https://blog.csdn.net/lizhengru2011/article/details/80275941 版权声明:本文为博主原创文章,转载请附上博文链接!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读