I have a small app for taking a webcam image and putting this image into an sql database as binary data and that works fine. However i have a problem with a separate .net web page where i want to simply display the image on the page by the easiest means possible.
Here’s some example code but its not much because I’ve being trying bits and bobs from the top of my head and just don’t have a clue if I’m anywhere near the solution.
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings["ConnectionString"];
SqlConnection con = new SqlConnection(settings.ConnectionString);
SqlCommand MyCmd;
MyCmd = new SqlCommand("SELECT image FROM contractors WHERE number like @number", con);
MyCmd.Parameters.AddWithValue("@number", "1");
Image1 = MyCmd.ExecuteScalar();
}
And to this i get the error message
Error 1 Cannot implicitly convert type ‘object’ to ‘System.Web.UI.WebControls.Image’. An explicit conversion exists (are you missing a cast?)
But i don’t know if I’m along the right lines so I’ve posted here not just specifically about that, but about what I’m trying to do overall.
You are assigning the result of the query directly to the
Imagevariable – this will never work, since theImagecontrol needs a URL in order to display an image on an ASP.NET page.The most common approach is to write an Http Handler that will return the image data and use the handler URL as the
ImageUrl.See this MSDN page about Http Handlers, and this SO question on how to achieve what you are looking for.