Click here to Skip to main content
13,559,785 members
Rate this:
 
Please Sign up or sign in to vote.
Hi,
How to display DataGridView Image Details winform.
Image

SQL Data Base
ID:1001
Image(Photo):image
Name:aaa
Age:25
Gender:M
Time:9.30 am

ID:1002
Image(Photo):image
Name:bbb
Age:26
Gender:M
Time:9.31 am

ID:1003
Image(Photo):image
Name:ccc
Age:26
Gender:M
Time:9.30 am

In DataGridView Like that show
1001 [Image] 25 M 
aaa       
9.30 am

1002 [Image] 26 M
bbb
9.31 am

1003 [Image] 26 M 
ccc         
>9.30 am

Regards,
Karthikeyan,
Bangalore.
Posted 15-Oct-12 0:30am
Updated 15-Oct-12 4:40am
v3
Comments
I.explore.code 15-Oct-12 6:35am
   
You mean you want to show the image thumbnail in DataGridView?
pkarthionline 15-Oct-12 7:04am
   
yes
I.explore.code 15-Oct-12 7:10am
   
Your question is misleading because you have tagged ASP.NET but you are talking about DataGridView and WinForms. You would have to make sure what you are looking for a solution for, none of the solutions posted here are for WinForms they would only work for ASP.NET.
pkarthionline 15-Oct-12 7:13am
   
winforms c#.net only.
I.explore.code 15-Oct-12 7:24am
   
I have posted a potential solution for WinForms. Have a look, its not a ready-made code but something for you to work with and improve on.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

hi. . .

This will be useful to retrieve the image from database, to display in a gridview

<asp:GridView runat="server" DataKeyNames="imageid" ID="Gridview1">

      <Columns>
         <asp:TemplateField HeaderText="Image">
            <ItemTemplate>

               <img src="ImageRetrive.aspx?imageid=<%# Eval("imageid") %>" height="200px" width="200px" alt="Available" />

            </ItemTemplate>
         </asp:TemplateField>
      </Columns>

      </asp:GridView>



Write the below in the page_load of imageRetrive.aspx


protected void Page_Load(object sender, EventArgs e)
   {
       int imageid = int.Parse(Request.QueryString["imageid"].ToString());

       string ConnString = ConfigurationManager.ConnectionStrings["connstr"].ConnectionString;

       byte[] byeteArray = new byte[5000];

       using (SqlConnection con = new SqlConnection(ConnString))
       {
           using (SqlCommand cmd = new SqlCommand("select myimage from storeimages where imageid="+imageid, con))
           {


               con.Open();
               byeteArray = (byte[])cmd.ExecuteScalar();
               Response.BinaryWrite(byeteArray);
               con.Close();
           }
       }



   }
  Permalink  
Comments
I.explore.code 15-Oct-12 7:08am
   
I would recommend using an HttpHandler instead of an aspx page. Works better if there is no UI needed to be shown and only backend processing is required.
Samsani.v.s.Durga Prasad 15-Oct-12 7:19am
   
There no ui in ImageRetrive.aspx. For getting the image ImageRetrive.aspx will be useful
I.explore.code 15-Oct-12 7:22am
   
well as it turns out, the question is for Winforms and not for ASP.NET. Blame the OP ;)
Samsani.v.s.Durga Prasad 15-Oct-12 7:30am
   
ok after try i will reply thanks
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

This is not the full solution but it will give you an idea to move in a direction. You are gonna have to do some work yourself to improvise this code, particularly to get a small size of the image to display as a thumbnail (that's an exercise for you).

SqlConnection conn = new SqlConnection("connection string");
            conn.Open();
            string get = "select * from Table1";
            SqlDataAdapter da = new SqlDataAdapter();
            
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = get;
            cmd.Connection = conn;

            da.SelectCommand = cmd;
            DataSet ds = new System.Data.DataSet();
            da.Fill(ds);
            byte[] img = null;
//in my case the fourth column has an image
img = (byte[]) ds.Tables[0].Rows[0][3];
            MemoryStream ms = new MemoryStream(img);
//for some reason this does not seem be creating a thumbnail
            Image.GetThumbnailImageAbort cb = new Image.GetThumbnailImageAbort(ThumCallBack);
            Image thumb = Image.FromStream(ms).GetThumbnailImage(10, 10, cb, IntPtr.Zero);
//theoretically, save the thumbnail back to the memory stream we opened above
            thumb.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
//read it back into the img array
            ms.Read(img, 0, img.Length);
//put it back in the dataset before we actually bind the data to the DataGridView
            ds.Tables[0].Rows[0][3] = img;
            dataGridView1.DataSource = ds.Tables[0];
...
public bool ThumCallBack()
        {
            return true;
        }


Hope this helps a bit.
  Permalink  
v2

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web03 | 2.8.180527.1 | Last Updated 15 Oct 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100