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

C# - How To Retrieve Image From MySQL Database In C#

__________________________________________________________________________

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


Project 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;
using System.IO;

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

        public Csharp_retrieve_image_from_mysql_database()
        {
            InitializeComponent();
        }

        private void BTN_SHOW_Click(object sender, EventArgs e)
        {

            String selectQuery = "SELECT * FROM db_images.myimages WHERE ID = '"+textBoxID.Text+"'";

            command = new MySqlCommand(selectQuery, connection);

            da = new MySqlDataAdapter(command);

            DataTable table = new DataTable();

            da.Fill(table);

            textBoxNAME.Text = table.Rows[0][1].ToString();
            textBoxDESC.Text = table.Rows[0][2].ToString();

            byte[] img = (byte[])table.Rows[0][3];

            MemoryStream ms = new MemoryStream(img);

            pictureBox1.Image = Image.FromStream(ms);

            da.Dispose();

        }
    }
}


=> OUTPUT :

Retrieve Image From MySQL Database




Share this

Related Posts

Previous
Next Post »

1 comments:

comments
29 décembre 2015 à 20:46 delete

Exelente me sirvio de mucho gracias

Reply
avatar