从mysql数据库C#中检索Blob图片 [英] retrieve blob picture from mysql database c#

查看:95
本文介绍了从mysql数据库C#中检索Blob图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用此代码来检索我的图片,它与仅包含blob的简单表紧密协作,但是当我尝试将其调整为包含(cin,nom,prenom ....,image)的表用户时)表示

I use this code to retrieve my picture and it work corectly with a simple table that contain only blob but when i'm trying to adapt it for my table user that containt (cin,nom,prenom....,image) exception that indicate

参数无效"(无效参数)

        int bufferSize = 1000; 
        try
        {
            string SQL = "Select image from user ";

            MySqlCommand cmd = new MySqlCommand(SQL, db.Connection);
            MySqlDataAdapter da = new MySqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds, "image");
            int c = ds.Tables["image"].Rows.Count;
            db.CloseConnection();

            if (c > 0)
            {
                Byte[] byteBLOBData = new Byte[bufferSize];
                byteBLOBData = (Byte[])(ds.Tables["image"].Rows[c - 1]["image"]);
                MemoryStream stmBLOBData = new MemoryStream(byteBLOBData);

                pictureBox1.Image = Image.FromStream(stmBLOBData);
                MessageBox.Show("bien chargée");
            }

        }
        catch (Exception ex)
        {
            MessageBox.Show("Connection Error!\n" + ex.Message, "Error Message",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

推荐答案

byteBLOBData = ((Byte[])ds.Tables["image"].Rows[c - 1]["image"]);

这应该解决它.

这篇关于从mysql数据库C#中检索Blob图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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