T
Tim
Hi,
I have a list of products in with images stored in a SQL Server 2000 DB. I
need to be able to retrieve the images when a product is chose. I use the
code below to get the image from the DB and assign it to the picture box.
It works fine the first time but subsequent times it gives me an error
saying that the file is in use by another process. What process? If I go to
the folder and try to delete the file in windows I get the same error. Can
anyone help me here? What am I doing wrong? I am closing the filestream so
what is still open?
Thanks
Tim
try
{
//Look Up the Image
SqlCommand cmdSelect=new SqlCommand("SELECT logo_image FROM
t_store_information WHERE store_id =1" , DBConnection.DBConn.Connection);
DBConnection.DBConn.Connection.Open();
byte[] barrImg=(byte[])cmdSelect.ExecuteScalar();
DBConnection.DBConn.Connection.Close();
string strfn=Convert.ToString(DateTime.Now.ToFileTime());
FileStream fs = new FileStream(@"C:\Program Files\MM\Temp\thumb.jpg",
FileMode.OpenOrCreate, FileAccess.Write);
fs.Write(barrImg,0,barrImg.Length);
fs.Close();
strfn = "";
this.pboxThumb.Image = Image.FromFile(@"C:\Program
Files\MM\Temp\thumb.jpg");
}
catch(Exception ex)
{
#if DEBUG
MessageBox.Show("Image Error!\r\n\r\n" + ex.Message);
#endif
}
finally
{
DBConnection.DBConn.Connection.Close();
}
I have a list of products in with images stored in a SQL Server 2000 DB. I
need to be able to retrieve the images when a product is chose. I use the
code below to get the image from the DB and assign it to the picture box.
It works fine the first time but subsequent times it gives me an error
saying that the file is in use by another process. What process? If I go to
the folder and try to delete the file in windows I get the same error. Can
anyone help me here? What am I doing wrong? I am closing the filestream so
what is still open?
Thanks
Tim
try
{
//Look Up the Image
SqlCommand cmdSelect=new SqlCommand("SELECT logo_image FROM
t_store_information WHERE store_id =1" , DBConnection.DBConn.Connection);
DBConnection.DBConn.Connection.Open();
byte[] barrImg=(byte[])cmdSelect.ExecuteScalar();
DBConnection.DBConn.Connection.Close();
string strfn=Convert.ToString(DateTime.Now.ToFileTime());
FileStream fs = new FileStream(@"C:\Program Files\MM\Temp\thumb.jpg",
FileMode.OpenOrCreate, FileAccess.Write);
fs.Write(barrImg,0,barrImg.Length);
fs.Close();
strfn = "";
this.pboxThumb.Image = Image.FromFile(@"C:\Program
Files\MM\Temp\thumb.jpg");
}
catch(Exception ex)
{
#if DEBUG
MessageBox.Show("Image Error!\r\n\r\n" + ex.Message);
#endif
}
finally
{
DBConnection.DBConn.Connection.Close();
}