Skip to content Skip to sidebar Skip to footer

VB.Net Retrieve Image From MySQL

How To Display Image From MySQL Database Using VbNet

 How To Display Image From MySQL Database Using VbNet VB.Net Retrieve Image From MySQL

In This VB.Net Tutorial  We Will See How To Get The ID From TextBox And Search In Database Image + Data With This Specific ID And Display The Picture Into PictureBox And The Other Data Into TextBoxes Using MySqlDataAdapter And DataTable In Visual Basic.Net  Programming Language And Visual Studio Editor.


Project Source Code:

Imports MySql.Data.MySqlClient
Imports System.IO

Public Class Display_Image_From_MySQL

    Dim connection As New MySqlConnection("datasource=localhost;port=3306;username=root;password=;database=s_t_d")

    Private Sub ButtonShow_Click(sender As Object, e As EventArgs) Handles ButtonShow.Click

        Dim command As New MySqlCommand("SELECT `id`, `name`, `dscp`, `pic` FROM `mypics` WHERE `id` = @ID", connection)
        command.Parameters.Add("@ID", MySqlDbType.UInt64).Value = TextBoxID.Text

        Dim adapter As New MySqlDataAdapter(command)
        Dim table As New DataTable()


        Try

            adapter.Fill(table)

            Dim imgByte() As Byte

            If table.Rows.Count = 1 Then

                TextBoxName.Text = table(0)(2)
                TextBoxDesc.Text = table(0)(2)
                imgByte = table(0)(3)

                Dim ms As New MemoryStream(imgByte)
                PictureBox1.Image = Image.FromStream(ms)

            Else

                MessageBox.Show("No Data Found")

                TextBoxName.Text = ""
                TextBoxDesc.Text = ""

                PictureBox1.Image = Nothing

            End If

        Catch ex As Exception

            MessageBox.Show("ERROR")

            TextBoxName.Text = ""
            TextBoxDesc.Text = ""

            PictureBox1.Image = Nothing

        End Try

    End Sub

End Class
      
///////////////OUTPUT:

 How To Display Image From MySQL Database Using VbNet VB.Net Retrieve Image From MySQL




Post a Comment for "VB.Net Retrieve Image From MySQL"