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:\Users\Administrator\Desktop";//文件选择的默认路径
if ((bool)openFileDialog.ShowDialog())
{
if ((ms = openFileDialog.OpenFile()) != null)
{
picByte = new byte[ms.Length];
ms.Position = 0;
ms.Read(picByte, 0, 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
版权声明:本文为博主原创文章,转载请附上博文链接!
相关文章
- 10-05图片与base64转换
- 10-05WPF 导出Excel 导出图片
- 10-05基础:enctype 包含上传input时必须(解决图片上传不成功问题)
- 10-05图片在线url转base64
- 10-05struts图片上传
- 10-05jsp实现将图片与文字同时上传
- 10-05将base64转为图片
- 10-05VUE上传图片、二级联动
- 10-05formidable上传图片
- 10-05Maven : 将Jar安装到本地仓库和Jar上传到私服[转]