I have 9 image paths for a product database I'm working on. I'd like to set their values from the database to each picture box.

I've already configured MySQL to localhost and can connect.

        string connStr = "server=localhost;user=root;database=possystem;port=3306;password=mypass";
        MySqlConnection conn = new MySqlConnection(connStr);
        try
        {
            conn.Open();
            string sql = "SELECT prodimg FROM Products";
            MySqlCommand cmd = new MySqlCommand(sql, conn);
            MySqlDataReader rdr = cmd.ExecuteReader();
            while (rdr.Read())
            { //Some code

            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
            throw;
        }

1 Answers

0
E. Mamaghani On

First of all this is not good idea to store image path in database! Second, specify that if your images paths are URL (From web) or just local.

If you are working with URL, get the URL from database & use Load method. (Resource):

.Load(string url);

If you are loading images from a local storage use:

Picturebox.Image = New Bitmap("Image Path");