retrieve blob picture from mysql database c#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • koanas
    New Member
    • Feb 2016
    • 1

    retrieve blob picture from mysql database c#

    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

    "Paramétre non valid" (not a valid parameter)
    Code:
            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);
            }
    Last edited by Rabbit; Mar 1 '16, 02:00 AM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • madankarmukta
    Contributor
    • Apr 2008
    • 308

    #2
    May I please know at which line it is giving an error ?

    Comment

    Working...