I am new to ASP & C# and have been unable to figure out how to do this.
I am loading BLOB's from a bd via an .ashx
file like so <img src="getimage.ashx" />
and it works fine, but sometimes there is no BLOB or it is empty.
here is the basic code
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DataSource.iMIS.Connection"].ConnectionString);
SqlCommand cmd = new SqlCommand("SELECT PICTURE_LOGO FROM Name_Picture WHERE ID = @EmpID", con);
cmd.CommandType = CommandType.Text;
cmd.Parameters.Add("@EmpID", id);
con.Open();
byte[] pict = (byte[])cmd.ExecuteScalar();
con.Close();
ctx.Response.ContentType = "image/bmp";
ctx.Response.OutputStream.Write(pict, 0, pict.Length);
My thought is to check pict.Length
right after con.Close()
and if it fails, I want to display a default image, or even text.
Is that possible? How?