0
I wonder if there’s any way to make it work here
int chck = 0;
int fid = 0;
        while (chck < 150)
        {
            try
            {
                sqlcon.Open();
                string sql2 = "SELECT img FROM clienteimg WHERE ((clienteid = '" + cid + "') AND (id = '" + fid + "'))";
                SqlCommand cmd2 = new SqlCommand(sql2, sqlcon);
                SqlDataReader dr2 = cmd2.ExecuteReader();
                dr2.Read();
                byte[] imgLoc = (byte[])dr2[0];
                sqlcon.Close();
                MemoryStream mstream = new MemoryStream(imgLoc);
                pb1.Image = Image.FromStream(mstream);
            }
            catch (Exception)
            {
                sqlcon.Close();
                sqlcon.Open();
                string foid = "9";
                string sql3 = "SELECT img FROM ClienteImgDB WHERE id = '" + foid + "'";
                SqlCommand cmd3 = new SqlCommand(sql3, sqlcon);
                SqlDataReader dr3 = cmd3.ExecuteReader();
                dr3.Read();
                byte[] imgLoc = (byte[])dr3[0];
                sqlcon.Close();
                MemoryStream mstream = new MemoryStream(imgLoc);
                pb1.Image = Image.FromStream(mstream);
            }
            chck++;
            fid++;
        }
being that, there in Pb1.Image (picturebox1 for those who did not understand), I wanted the number to be flexible, I know that the following example does not work, but I hope you understand where I want to get
int chck = 0;
int fid = 0;
        while (chck < 150)
        {
            try
            {
                sqlcon.Open();
                string sql2 = "SELECT img FROM clienteimg WHERE ((clienteid = '" + cid + "') AND (id = '" + fid + "'))";
                SqlCommand cmd2 = new SqlCommand(sql2, sqlcon);
                SqlDataReader dr2 = cmd2.ExecuteReader();
                dr2.Read();
                byte[] imgLoc = (byte[])dr2[0];
                sqlcon.Close();
                MemoryStream mstream = new MemoryStream(imgLoc);
                pb'"+fid+"'.Image = Image.FromStream(mstream);
            }
            catch (Exception)
            {
                sqlcon.Close();
                sqlcon.Open();
                string foid = "9";
                string sql3 = "SELECT img FROM ClienteImgDB WHERE id = '" + foid + "'";
                SqlCommand cmd3 = new SqlCommand(sql3, sqlcon);
                SqlDataReader dr3 = cmd3.ExecuteReader();
                dr3.Read();
                byte[] imgLoc = (byte[])dr3[0];
                sqlcon.Close();
                MemoryStream mstream = new MemoryStream(imgLoc);
                pb'"+fid+"'.Image = Image.FromStream(mstream);
            }
            chck++;
            fid++;
        }
so that every time I rotate the loop, the "pb" is added in another 1 to fill the 150 pictureboxes I have
Seeing the code and even you explaining, I don’t understand what you mean by flexible number. What is the specific error you’re encountering? You want to create objects dynamically?
– Leandro Angelo