How To Make Images SlideShow From MySQL Database In Visual Basic.Net
In This VB.Net and MySQL Tutorial We Will See How To Make an Image SlideShow With Images From MySQL Database Table Using Visual Basic.Net Programming Language And Visual Studio Editor.
we need to create two buttons:
1- ">" => go to the next image
2- "<" => go to the previous image
- To Learn More Watch The Video Tutorial Below.
we need to create two buttons:
1- ">" => go to the next image
2- "<" => go to the previous image
- To Learn More Watch The Video Tutorial Below.
Project Source Code:
Imports MySql.Data.MySqlClient
Imports System.IO
Public Class Images_Slider_From_MySQL
' create a connectio with mysql database
Dim connection As New MySqlConnection("datasource=localhost;port=3306;username=root;password=;database=vbnet_student_db")
' table to store images
Dim table As New DataTable()
' the row index for the images
Dim rowIndex As Integer
' form load
Private Sub Images_Slider_From_MySQL_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim command As New MySqlCommand("SELECT picture FROM `student`", connection)
Dim adapter As New MySqlDataAdapter(command)
adapter.Fill(table)
rowIndex = 0
displayImage()
End Sub
' create a sub to display images using the row index
Sub displayImage()
Dim imgByte As Byte()
imgByte = table(rowIndex)(0)
Dim ms As New MemoryStream(imgByte)
PictureBox1.Image = Image.FromStream(ms)
End Sub
' button next
Private Sub Button_Next_Click(sender As Object, e As EventArgs) Handles Button_Next.Click
If rowIndex <= table.Rows.Count - 2 Then
rowIndex = rowIndex + 1
displayImage()
End If
End Sub
' button previous
Private Sub Button_Previous_Click(sender As Object, e As EventArgs) Handles Button_Previous.Click
If rowIndex >= 1 Then
rowIndex = rowIndex - 1
displayImage()
End If
End Sub
End Class
///////////////OUTPUT:
Download Projects Source Code