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
版权声明:本文为博主原创文章,转载请附上博文链接!
转载于:https://www.cnblogs.com/LiZhongZhongY/p/11066895.html