I am pulling the data from ms sql server image field. The byte array is formed like this
public byte[] saveImageBlob(string number)
{
string strSql = "select pic from emp where number like '" + number + "'";
SqlCommand cmd = new SqlCommand(strSql, conn);
SqlDataReader MyReader = cmd.ExecuteReader();
if (MyReader.Read())
{
byte[] m_MyImage = (byte[])MyReader["pic"];
return m_MyImage;
}
return null;
}
Then i call the array in my page_load function and put it in the filestream like this
Employee emp = new Employee();
emp.getEmployee(Request.QueryString["user"]);
string file_name = System.AppDomain.CurrentDomain.BaseDirectory + "/img/" + emp.Number.ToString() + ".bmp";
System.IO.FileStream _FileStream = new System.IO.FileStream(file_name, System.IO.FileMode.Create, System.IO.FileAccess.Write);
_FileStream.Write(emp.Picture, 0, emp.Picture.Length);
_FileStream.Close();
The employee class does nothing but pass the data between page_load and my db class.
The file is saved in the right place with the right name and the size looks correct. But i cant open it or see the picture. The file is corrupt.
The client told me that the image field in the sql server contains BMP images.
I am a bit lost here, has anyone had experience with working with mssql blobs?
Is there any way i can see if the image/blob field is corrupt in the DB?
Am i missing something crucial in my code?
With regards, ssg.