I'm trying to load my pictures into dynamically created pictureboxes. The pictures will be retrieved from a mysql server which is located on my local network. I've been able to get one picture in a picturebox by changing the query to pick only 1 id. so I know it works with one at the time.
Code:
private void ass_wijzig_Load(object sender, EventArgs e)
{
string query = "Select Image From Product";
MySqlCommand cmd = new MySqlCommand(query,connection);
// MySqlDataReader reader = cmd.ExecuteReader();
var da = new MySqlDataAdapter(cmd);
var ds = new DataSet();
da.Fill(ds, "Image");
int count = ds.Tables["Image"].Rows.Count;
DataRow myrow;
byte[] mydata = new byte[0];
int x = 10;
int y = 10;
for (int i = 0; i < 2; i++)
{
myrow= ds.Tables["Image"].Rows[i];
// var data = (Byte[])(ds.Tables["Image"].Rows[i]["Image"]);
mydata = (Byte[])(ds.Tables["Image"].Rows[i]["Image"]);
Stream[] str = new MemoryStream[i];
str[i] = new MemoryStream(mydata);
PictureBox[] pbx = new PictureBox[i];
pbx[i] = new PictureBox();
pbx[i].Size = new Size(150, 150);
pbx[i].SizeMode = PictureBoxSizeMode.StretchImage;
pbx[i].Image = Image.FromStream(str[i]);
pbx[i].Visible = true;
pbx[i].Location = new Point(x, y);
x += pbx[i].Location.X + pbx[i].Width;
this.Controls.Add(pbx[i]);
}
The exception is thrown at Stream[] str = new MemoryStream[i];
I would be honored if somebody knew the problem,
Thanks in advance