Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 4.0 从MS Access检索图像_C# 4.0 - Fatal编程技术网

C# 4.0 从MS Access检索图像

C# 4.0 从MS Access检索图像,c#-4.0,C# 4.0,我想从ms access数据库中检索一个图像,并用此代码显示在PictureBox中 我的代码如下: private void button1_Click(object sender, EventArgs e) { OleDbConnection myConnection = new OleDbConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

我想从ms access数据库中检索一个图像,并用此代码显示在PictureBox中 我的代码如下:

private void button1_Click(object sender, EventArgs e)
    {
        OleDbConnection myConnection = new OleDbConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

        myConnection.Open();
        OleDbCommand cmd = new OleDbCommand("select * from [Images] where ID=1", myConnection);
        OleDbDataAdapter da = new OleDbDataAdapter(cmd);
        DataTable dt = new DataTable();
        da.Fill(dt);

        if (dt.Rows.Count > 0)
        {
            if (dt.Rows[0]["AImage"] != DBNull.Value)
            {
                pictureBox.Image = ByteArrayToImage((Byte[])dt.Rows[0]["AImage"]);
            }
        }
        myConnection.Close();   

    }

    Bitmap ByteArrayToImage(byte[] b)
    {
        MemoryStream ms = new MemoryStream();
        byte[] pData = b;
        ms.Write(pData, 0, Convert.ToInt32(pData.Length));
        Bitmap bm = new Bitmap(ms, false);
        ms.Dispose();
        return bm;
    }
但存在如下错误:参数无效。对于位图bm=新位图,为false;
我不知道为什么

来自位图构造函数的MSDN文档:Bitmapstream,布尔值

如果出现以下情况,将引发System.ArgumentException:

流不包含图像数据或为空

-或-

流包含单个维度大于的PNG图像文件 65535像素

评论 您必须在位图的生存期内保持流打开

由于GDI+解码器的限制,System.ArgumentException 如果从带有 单个尺寸大于65535像素

您是否检查了从Access数据库检索的映像的属性,以查看这是否描述了您的错误情况