0
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=PROMOD-PC;Initial Catalog=travel_Directions;Integrated Security=True";


DataTable dt = new DataTable();

String selQuery = "SELECT Image FROM MapDataImage WHERE Source='" + TextBox1.Text + "';";

SqlCommand SelCmmnd = new SqlCommand(selQuery);
SqlDataAdapter sDatAdp = new SqlDataAdapter();
SelCmmnd.CommandType = CommandType.Text;
SelCmmnd.Connection = con;

con.Open();

sDatAdp.SelectCommand = SelCmmnd;

sDatAdp.Fill(dt);
ListView1.DataSource = dt;
ListView1.DataBind();

con.Close();
sDatAdp.Dispose();
con.Dispose();
dt.Dispose();

guys now code is ready...(execute without an error) but when i clicked the button... it will show label like Image: System.Byte[].... in list view is there any problem in the code?

Is this code wrong? someone please help me? to figure this out............

  • 2
    You need to add a generic handler to render the actual image - see this answer (Duplicate) http://stackoverflow.com/questions/21877/dynamically-rendering-aspimage-from-blob-entry-in-asp-net – Darren Wainwright Jul 04 '13 at 13:31

1 Answers1

0

The behavior you describe sounds like you are calling .ToString() on an Image object. Images are not strings, so the .ToString() method will perform the default behavior of writing the class name and a property like System.Byte[] to the label. Darren's link in the comments shows how to write an array of bytes to the response stream, though if you really really want to keep it a string and the image size is small you can also try using the data:uri format for image tags:

stackoverflow.com/questions/6826390/...

I'd go with the custom httphandler to write to stream, since the data uri format might not be supported with all browsers and has a size limit. But, if you're just serving small images to modern browsers, it may be for you.

Community
  • 1
  • 1
welegan
  • 3,013
  • 3
  • 15
  • 20