PDA

View Full Version : سوال: ارور System Out Of Memory



shytonak
پنج شنبه 20 آبان 1389, 11:36 صبح
سلام دوستان من وفتی می خوام یه عکس از دیتابیس لود کنم با این ارور مواجه می شم مشکل چیه؟

صباح فتحی
پنج شنبه 20 آبان 1389, 11:37 صبح
کد لود رو بزار خب

shytonak
پنج شنبه 20 آبان 1389, 11:45 صبح
private OleDbConnection con;
private OleDbCommand cmd;
private OleDbDataReader re;
private MemoryStream MS;
private byte[] Pic;
private string strQuery = string.Empty;

private string ConnectionString()
{
string ConString = @"Provider=Microsoft.Jet.OLEDB.4.0;"+
@"Data Source=Database2.mdb";
return (ConString);
}



private void btnshow_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.txtidfornshow.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.picboxMyimage.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();
}
}
}

صباح فتحی
پنج شنبه 20 آبان 1389, 11:48 صبح
خیلی کد لود رو پیچوندی اینو واسش بنویس:

{
try
{
strsql = "SELECT photo FROM tb_persion where id=" + txtload.Text;
com = new SqlCommand(strsql, con);

con.Open();
byte[]Ax=(byte[])(com.ExecuteScalar());
con.Close();
MemoryStream ms = new MemoryStream(Ax);
picload2.Image = Bitmap.FromStream(ms);
}
catch (Exception ex)
{

MessageBox.Show(ex.Message);
}

}

shytonak
پنج شنبه 20 آبان 1389, 12:15 عصر
دوست من میشه بگید strsql و com چی هستند؟
با تشکر

صباح فتحی
پنج شنبه 20 آبان 1389, 12:26 عصر
اینم برنامش
فقط بانکشو ندارم.گمش کردم

shytonak
پنج شنبه 20 آبان 1389, 21:22 عصر
دوست من نمی دونم مشکل کجاست ولی وقتی باتن لود رو فشار می دم ارور زیر رو می ده.
Object reference not set to an instance of an object.