Keep inserting the same image to DB
Greetings all,
I have made a form on my C# application for adding new images (and info about the image) into a MSSQL 2000 database. I have two buttons for adding the image; one for adding it and closing the form and one for adding it keeping the form open to add another. Both call on the same functions to add the image but when I try to add another, it always adds the same image as it did the first time.
My question is, when you declare a byte[] inside a function, does the byte[] not get reset the next time the function is called? If not, is there a way that I can destroy the byte array at the end of the function to make sure the same data doesn't get added the next time the function is called. My byte arrays inside the function are declared like this:
byte[] rawstandard = GetPhoto(standpath);
byte[] rawthumb = GetPhoto(thumbpath);
rawstandard and rawthumb are the standard size and thumbnail size raw byte arrays. standpath and thumbpath are the absolute paths of the image files (They get created at the beginning of the function and deleted at the end of the function). The GetPhoto function looks like this:
public static byte[] GetPhoto(string filePath)
{
FileStream fs = new FileStream(filePath, FileMode.Open,
FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
byte[] photo = br.ReadBytes((int)fs.Length);
br.Close();
fs.Close();
return photo;
}
Can anyone see a reason why it would be using the same byte data the second time as it would the first, even though the files in standpath and thumbpath have changed?
Regards,
Devon
|