Skander Baatout

Skander Baatout

  • 1.6k
  • 3
  • 350

Load image

Apr 26 2023 9:13 AM

Please anyone can help me to load image from sql server , it's already added in the database successfully but couldn't be loaded in the picture box ...
Here is the code 


 

 if (ds.Tables[0].Rows[i][6] != DBNull.Value)
                    {
                        label_question.Text = ds.Tables[0].Rows[i][0].ToString();
                        radioButton1.Text = ds.Tables[0].Rows[i][1].ToString();
                        radioButton2.Text = ds.Tables[0].Rows[i][2].ToString();
                        radioButton3.Text = ds.Tables[0].Rows[i][3].ToString();
                        radioButton4.Text = ds.Tables[0].Rows[i][4].ToString();

                        // Récupérer les données d'image depuis la colonne de la base de données
                        byte[] img = (byte[])ds.Tables[0].Rows[i][6];

                        if (img != null && img.Length > 0)
                        {
                            try
                            {
                                // Créer une image à partir des données d'image
                                using (MemoryStream ms = new MemoryStream(img))
                                {
                                    Image image = Image.FromStream(ms);
                                    pictureBox.Image = image;
                                    pictureBox.SizeMode = PictureBoxSizeMode.StretchImage;
                                }
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show("Une erreur s'est produite lors de la manipulation de l'image : " + ex.Message, "Erreur");
                            }


Answers (1)