Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > how to bind image (binary data) into a binding control
 

how to bind image (binary data) into a binding control

how to bind image(binary data) into a binding control I have data table contains images as as in database. I want to bind the images into a rectangular box(which can contain other controls like label) at run time and I should be able to get a click event for it. 4 columns* n rows
Thanks, Bharathi
bharathi_m  Monday, September 28, 2009 11:30 AM

Hi,

 

Do you mean you want to show image in the control like picture box? You can get the image using MemoryStream object.

Please refer to the following links.

1. How To Display an Image from a Database in a Windows Forms PictureBox by Using Visual Basic .NET

http://support.microsoft.com/kb/321900/en-us

2. HOW TO: Copy a Picture from a Database Directly to a PictureBox Control with Visual C#

http://support.microsoft.com/kb/317701/en-us

 

If you bind datasource which contains image column to datagridview, set the datasource will be ok.

                conn = new SqlConnection("Data Source=.;user = sa;password = sa;database = factory");

                SqlCommand comm = new SqlCommand();

                comm.Connection = conn;

                comm.CommandText = "select name, image from imagetest";

                adapter = new SqlDataAdapter(comm);

                adapter.Fill(dt1);

                dataGridView1.DataSource = dt1;

// add another imageColumn

                DataGridViewImageColumn img = new DataGridViewImageColumn();

                img.DataPropertyName = "image";

                img.Name = "test";

 

                dataGridView1.Columns.Add(img);

 

            // bind image to picturebox

            pictureBox1.DataBindings.Add("image",dt1,"image",true);

 

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Sunday, October 04, 2009 6:37 AM

Hi,

 

Do you mean you want to show image in the control like picture box? You can get the image using MemoryStream object.

Please refer to the following links.

1. How To Display an Image from a Database in a Windows Forms PictureBox by Using Visual Basic .NET

http://support.microsoft.com/kb/321900/en-us

2. HOW TO: Copy a Picture from a Database Directly to a PictureBox Control with Visual C#

http://support.microsoft.com/kb/317701/en-us

 

If you bind datasource which contains image column to datagridview, set the datasource will be ok.

                conn = new SqlConnection("Data Source=.;user = sa;password = sa;database = factory");

                SqlCommand comm = new SqlCommand();

                comm.Connection = conn;

                comm.CommandText = "select name, image from imagetest";

                adapter = new SqlDataAdapter(comm);

                adapter.Fill(dt1);

                dataGridView1.DataSource = dt1;

// add another imageColumn

                DataGridViewImageColumn img = new DataGridViewImageColumn();

                img.DataPropertyName = "image";

                img.Name = "test";

 

                dataGridView1.Columns.Add(img);

 

            // bind image to picturebox

            pictureBox1.DataBindings.Add("image",dt1,"image",true);

 

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Sunday, October 04, 2009 6:37 AM

You can use google to search for other answers

Custom Search

More Threads

• C# and Crystal report creating a report
• datatable.acceptchanges updates more than one table
• Strange problem with DataGridViewComboBoxCell
• Error when i try to save to Database
• inserting name/value paris in DataGridViewComboBox Cell
• combobox inside a DataGridView
• Why do I have to detach the database each time I run a project?
• Databinding with DataGridViewImageColumn
• Datagrid one column only accept numbers
• Strong-typed Datagridviewrow.count=900 but only 2 accessible (worked fine afterward)