Click here to Skip to main content
15,917,321 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
private void textBox1_TextChanged(object sender, EventArgs e)
       {


           try
           {
               cnn.Open();

               cmd.CommandText = "select * from Slab  where s_flatno=" + textBox1.Text;

               SqlDataReader dr1;
               dr1 = cmd.ExecuteReader();

               while (dr1.Read())
               {

                       dataGridView1.Rows.Add(dr1[1].ToString(), dr1[4].ToString(), dr1[5].ToString(), dr1[6].ToString(),dr1[7].ToString());
                       count = Convert.ToInt32(dataGridView1.Rows.Count.ToString());
                  }

               lblcount.Text = count.ToString();
               dr1.Close();
               cnn.Close();

           }
           catch (Exception ex)
           {
               MessageBox.Show(ex.ToString());
           }



       }


What I have tried:

in the above code im accessing database data to grid view ,but im not getting images in that. instead of geting image in getting byte string of the image ....

in the position on dr1[7].tostring() i want images instead of image byte code...
Posted
Updated 12-Feb-18 22:03pm
Comments
Animesh Datta 13-Feb-18 6:24am    
have you taken DataGridViewImageColumn in your datagrdiview control

1 solution

You can not simply bind binary image to a control. You have to create an HttpHandler(.ashx) that process the image.

using System;
using System.Web;

public class ImageHandler : IHttpHandler, IReadOnlySessionState
{

    public void ProcessRequest(HttpContext context)
    {
        context.Response.BinaryWrite(yourImageByte);// You must replace "yourImageByte" with image reader logic from database.
    }

    public bool IsReusable {
        get { return false; }
    }

}

Finally you can bind the image to the handler.

Image1.ImageUrl ="ImageHanderl.ashx"


read this - ASP.NET Futures - Generating Dynamic Images with HttpHandlers gets Easier - Scott Hanselman
 
Share this answer
 
v4
Comments
F-ES Sitecore 13-Feb-18 4:21am    
This is a windows app, not a website (made the same mistake myself :o )

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900