out of memory exception
-
hi every body, in my application i want to retrieve image from database and it will show on picture box, so my code is try { int no = int.Parse(textBox2.Text); SqlConnection con = new SqlConnection("user id=sa;password=sa123;server=192.168.0.44;database=eswar"); SqlCommand cmd = new SqlCommand("select imagedata from image1 where sno=" + no, con); //byte[] barrImg=(byte[])cmdSelect.ExecuteScalar(); cmd.Parameters.Add(textBox2.Text, SqlDbType.Int, 4); cmd.Parameters[textBox2.Text].Value = this.textBox2.Text; con.Open(); byte[] imgarr = (byte[])cmd.ExecuteScalar(); string strfn = Convert.ToString(DateTime.Now.ToFileTime()); FileStream fs = new FileStream(strfn, FileMode.CreateNew, FileAccess.Write); fs.Write(imgarr, 0, imgarr.Length); fs.Flush(); fs.Close(); pictureBox1.SizeMode = PictureBoxSizeMode.Normal; pictureBox1.Image = Image.FromFile(strfn); cmd.Dispose(); con.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } when my application is running it will shows a out of memory exception pls help me thanks in advance.........
-
hi every body, in my application i want to retrieve image from database and it will show on picture box, so my code is try { int no = int.Parse(textBox2.Text); SqlConnection con = new SqlConnection("user id=sa;password=sa123;server=192.168.0.44;database=eswar"); SqlCommand cmd = new SqlCommand("select imagedata from image1 where sno=" + no, con); //byte[] barrImg=(byte[])cmdSelect.ExecuteScalar(); cmd.Parameters.Add(textBox2.Text, SqlDbType.Int, 4); cmd.Parameters[textBox2.Text].Value = this.textBox2.Text; con.Open(); byte[] imgarr = (byte[])cmd.ExecuteScalar(); string strfn = Convert.ToString(DateTime.Now.ToFileTime()); FileStream fs = new FileStream(strfn, FileMode.CreateNew, FileAccess.Write); fs.Write(imgarr, 0, imgarr.Length); fs.Flush(); fs.Close(); pictureBox1.SizeMode = PictureBoxSizeMode.Normal; pictureBox1.Image = Image.FromFile(strfn); cmd.Dispose(); con.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } when my application is running it will shows a out of memory exception pls help me thanks in advance.........
First, comment out your try catch block, and then look at where it does happen. Second: Put your code into <pre></pre> blocks
-
hi every body, in my application i want to retrieve image from database and it will show on picture box, so my code is try { int no = int.Parse(textBox2.Text); SqlConnection con = new SqlConnection("user id=sa;password=sa123;server=192.168.0.44;database=eswar"); SqlCommand cmd = new SqlCommand("select imagedata from image1 where sno=" + no, con); //byte[] barrImg=(byte[])cmdSelect.ExecuteScalar(); cmd.Parameters.Add(textBox2.Text, SqlDbType.Int, 4); cmd.Parameters[textBox2.Text].Value = this.textBox2.Text; con.Open(); byte[] imgarr = (byte[])cmd.ExecuteScalar(); string strfn = Convert.ToString(DateTime.Now.ToFileTime()); FileStream fs = new FileStream(strfn, FileMode.CreateNew, FileAccess.Write); fs.Write(imgarr, 0, imgarr.Length); fs.Flush(); fs.Close(); pictureBox1.SizeMode = PictureBoxSizeMode.Normal; pictureBox1.Image = Image.FromFile(strfn); cmd.Dispose(); con.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } when my application is running it will shows a out of memory exception pls help me thanks in advance.........
see my sig. and use Exception.ToString() not Exception.Message :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages