110,537
社区成员
发帖
与我相关
我的任务
分享
using (SqlConnection cn = new SqlConnection("Server=.;UID=sa;Pwd=123456;Database=hzmkma_crm"))
{
using (SqlCommand cmd = new SqlCommand(" UPDATE makam_admin SET portrait=@pic where username=@username", cn))
{
cmd.Parameters.Add("@username", SqlDbType.NChar).Value = UserHelper.uuname;
cmd.Parameters.Add("@pic", SqlDbType.Image).Value = new byte[] { };
cn.Open();
int num= cmd.ExecuteNonQuery();
if (num > 0)
{
MessageBox.Show("图片插入成功!");
}
}
}
private byte[] SetImageToByteArray(string fileName)
{
FileStream fs = null;
try
{
fs = new FileStream(fileName, FileMode.Open, System.IO.FileAccess.Read, FileShare.ReadWrite);
Bitmap bt = new Bitmap(fs);
int streamLength = (int)fs.Length;
byte[] image = new byte[streamLength];
fs.Read(image, 0, streamLength);
return image;
}
catch (Exception)
{
throw;
}
finally
{
fs.Close();
}
}