首页 新闻 赞助 找找看

关于往数据库中提交图片出现GDI+一般性错误的处理方法,大神进

0
[已关闭问题] 关闭于 2012-11-16 09:28

情况是这样的,做的是winform,然后用的是PictureBox控件,现在出现这么个问题,我用PictureBox控件关联了一个OpenFileDialog,一般时候,PictureBox显示的是数据库表中的那个Image,当Update的时候,就把PictureBox中的图片Update上去,但是吧,当用PictureBox选择一张图片,也就是用OpenFileDialog选择一张图片再Update时不会出错,如果不选择图片,也就是不用OpenFileDialog选择图片,直接将PictureBox里的图片Update时(也就是不更新数据库表里的图片),会出现GDI+一般性错误这个异常

处理的代码如下

 

public static SqlParameter CreateSQLPara_Img(string name, ParameterDirection direction, System.Drawing.Image img)
        {
            SqlParameter p = new SqlParameter();
            p.ParameterName = name;
            p.SqlDbType = SqlDbType.Image;
            p.Direction = direction;
            //读写字节
            MemoryStream ms = new MemoryStream();
            byte[] imagedata = null;
            if (img != null)
            {
                img.Save(ms, img.RawFormat);  //这句话会报异常
                imagedata = ms.GetBuffer();
                ms.Close();
            }
            //
            p.SqlValue = imagedata;
            return p;
        }

求大神帮忙解决

微澜的主页 微澜 | 初学一级 | 园豆:-1
提问于:2012-11-07 08:52
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册