从Access数据库检索图像时参数无效错误 [英] parameter in not valid error while retrieving image from access database

查看:117
本文介绍了从Access数据库检索图像时参数无效错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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;
    }



数据字段的数据类型是oledbobject


datatype of the data field is oledbobject

推荐答案

它不在该代码中。 ..

见这里:为什么我得到参数无效。我从数据库中读取图像时出现异常? [ ^ ]
It's not in that code...
See here: Why do I get a "Parameter is not valid." exception when I read an image from my database?[^]


这篇关于从Access数据库检索图像时参数无效错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆