I'm having the wierdest problem. I'm trying to save images into a SQL 2005
database. the field is just called "IMAGES" and hte data type is "image".
here is my code to save
//following code saves an image as a byte array to a DB
string strFn = this.openFileDialog1.FileName;
this.pictureBox1.Image = Image.FromFile(strFn);
FileInfo fiImage = new FileInfo(strFn);
m_lImageFileLength = fiImage.Length;
FileStream fs = new FileStream(strFn, FileMode.Open, FileAccess.Read,
FileShare.Read);
fs.Seek(0, SeekOrigin.Begin);
m_barrImg = new byte[Convert.ToInt32(m_lImageFileLength)];
int iBytesRead = fs.Read(m_barrImg, 0, Convert.ToInt32(m_lImageFileLength));
fs.Close();
//method takes in customerID, and byte array of image data
savepicture(CustomerID, m_barrImg
//the following code pulls it back out
//first get the byte array back from SQL using this method.
Byte[] barrImg = DBAccess.getimage(CustomerID);
string strfn = Convert.ToString(DateTime.Now.ToFileTime());
FileStream fs1 = new FileStream(strfn, FileMode.CreateNew, FileAccess.Write);
fs1.Write(barrImg, 0, barrImg.Length);
fs1.Flush();
fs1.Close();
//try to display it
pictureBox1.Image = Image.FromFile(strfn);
my proble is that when I get it BACK, the byte array size is only 13! when I
put it in, it's much larger than that.
why is it always 13 ? what am I doing wrong? the methods for update and
select are basic UPDATE TABLE SET IMAGE = ' m_BarrImg ' WHERE CUSTOMERID =
(whatever) , and the SELECT is the same simplicity SELECT IMAGE WHERE
CUSTOMERID = (whatever).
why is this happening? I have tried to a couple hours now. thanks.
PS. NO stored procedures thanks. :)