WinFrom 如果以非独占的方式打开图片?

zhaozhijun0207 2009-01-17 05:06:45


strSql = "update sc生产制单_报表_款印绣辅图 set 列" + m.ToString() + "=@image where 生产制单号='" + a生产制单.编号 + "' ";
SqlCommand com2 = new SqlCommand(strSql, clsSql.cn);
SqlParameter sp2 = new SqlParameter("@image", SqlDbType.Image);
try
{
Stream ms2 = File.Open(strr列值, FileMode.Open, FileAccess.Read);
byte[] b2 = new byte[ms2.Length];
ms2.Read(b2, 0, b2.Length);
sp2.Value = b2;
com2.Parameters.Add(sp2);
try
{
com2.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
ms2.Dispose();
com2.Dispose();
}
catch (Exception)
{
MessageBox.Show("图片被另一个进程使用. 路径:" + strr列值.Trim());
continue;
}



我的源码,怎么改进,以非独占的方式使用图片?
...全文
169 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
crowzwong 2009-01-17
  • 打赏
  • 举报
回复
FileStream fs=new FileStream (openFile.FileName,FileMode.OpenOrCreate,FileAccess.Read);
byte[] imgbyte=new byte [fs.Length];
BinaryReader br=new BinaryReader(fs);
imgbyte=br.ReadBytes(Convert.ToInt32(fs.Length));
图片转二进制
crowzwong 2009-01-17
  • 打赏
  • 举报
回复
SqlDataReader sqldr = sql_class.GetDataReader("select Photo from tb_GoodsInfo where GoodsId='" + tbxGoodsId.Text.Trim() + "'");
sqldr.Read();
if (sqldr[0]!=DBNull.Value )
{
MemoryStream ms = new MemoryStream((byte[])sqldr["Photo"]);
pictureBox.Image = Image.FromStream(ms, true);
}
else
{
pictureBox.Image=null;
}
sqldr.Close();

我是这样读取的
xuqunying0545 2009-01-17
  • 打赏
  • 举报
回复
学习一下
zgke 2009-01-17
  • 打赏
  • 举报
回复
FileStream _FileStream1 = new FileStream(@"C:\1.jpg", FileMode.Open, FileAccess.Read, FileShare.Read);
FileStream _FileStream2 = new FileStream(@"C:\1.jpg", FileMode.Open, FileAccess.Read, FileShare.Read);

不知道是不是你要的效果
zgke 2009-01-17
  • 打赏
  • 举报
回复
FileStream _FileStream1 = new FileStream(@"C:\1.jpg", FileMode.Open, FileAccess.Read, FileShare.Read);
FileStream _FileStream2 = new FileStream(@"C:\1.jpg", FileMode.Open, FileAccess.Read, FileShare.Read);

不知道是不是你要的效果
wyg19861016 2009-01-17
  • 打赏
  • 举报
回复
每一次读取后都把图片保存到内存中 关闭连接 就可以了 不过会产生未提交读、幻想读或脏读
fancystyle 2009-01-17
  • 打赏
  • 举报
回复
Stream ms2 = File.Open(strr列值, FileMode.Open, FileAccess.Read);
这样用只读的方式异常的话
用这个吧
StreamReader sr = new StreamReader(xxxx);

111,130

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧