PDA

View Full Version : سوال: مشکل هنگام لود شدن تصویر از دیتابیس



shytonak
پنج شنبه 20 آبان 1389, 01:57 صبح
سلام دوستان من وقتی از دیتابیس می خوام عکس لود کنم با پیغام زیر روبرو میشم.من از کد زیر برای لود کرد استفاده می کنم.

private void button4_Click(object sender, EventArgs e)
{
this.con = new OleDbConnection(ConnectionString());

this.strQuery = "select img from tb1 where ID=@ID";

this.cmd = new OleDbCommand(this.strQuery, this.con);

this.cmd.Parameters.AddWithValue
("@ID", this.textBox1.Text.Trim());

this.con.Open();

this.re = this.cmd.ExecuteReader();

if (re.Read())
{
this.Pic = (byte[])re.GetValue(0);

this.MS = new MemoryStream();
this.MS.Write(this.Pic, 0, this.Pic.Length);

this.pictureBox18.BackgroundImage = Image.FromStream(this.MS);
this.Dispinse();
}
this.Dispinse();
}
private byte[] getByte(string addressPic)
{
this.Pic = File.ReadAllBytes
(addressPic);

return (this.Pic);
}

private void Dispinse()
{
if (this.Pic != null)
{
this.Pic = null;
}

if (this.MS != null)
{
this.MS.Dispose();
}

if (this.re != null)
{
this.re.Close();
}
if (this.con != null)
{
this.con.Close();
}
}