C# - How To Retrieve Image From MySQL Database To dataGridView Using C#

C# - How To Display Image From MySQL Database To dataGridView In C#

__________________________________________________________________________

In This C# Tutorial We Will See How To  Get Pictures From MySQL database
 To DataGridView In CSharp Programming Language .


Source Code :


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace Csharp_And_MySQL
{
    public partial class Csharp_retrieve_image_from_mysql_Database_To_dataGridView : Form
    {
        MySqlConnection connection = new MySqlConnection("datasource=localhost;port=3306;username=root;password=");
        MySqlCommand command;
        MySqlDataAdapter da;

        public Csharp_retrieve_image_from_mysql_Database_To_dataGridView()
        {
            InitializeComponent();
        }

        private void Csharp_retrieve_image_from_mysql_Database_To_dataGridView_Load(object sender, EventArgs e)
        {

            string selectQuery = "SELECT * FROM db_images.myimages";
            command = new MySqlCommand(selectQuery, connection);
            da = new MySqlDataAdapter(command);

            DataTable table = new DataTable();

            dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            dataGridView1.RowTemplate.Height = 100;
            dataGridView1.AllowUserToAddRows = false;

            da.Fill(table);

            dataGridView1.DataSource = table;

            DataGridViewImageColumn imageColumn = new DataGridViewImageColumn();
            imageColumn = (DataGridViewImageColumn)dataGridView1.Columns[3];
            imageColumn.ImageLayout = DataGridViewImageCellLayout.Stretch;

            da.Dispose();

        }
    }
}


=> OUTPUT:

Retrieve Image From Database To dataGridview




Share this

Related Posts

Previous
Next Post »