Affichage des articles dont le libellé est mysql database. Afficher tous les articles
Affichage des articles dont le libellé est mysql database. Afficher tous les articles

VB.Net Images Slider From MySQL Database

How To Make Images SlideShow From MySQL Database In Visual Basic.Net 

Images SlideShow From MySQL Using VBnet

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. 


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:



How To Make Images Slider From Database Using Vbnet



VB.NET - Calculate Percentage With MySQL

How To Calculate Percentage From MySQL Database In Visual Basic.Net 

Calculate Percentage With MySQL Using Vbnet

In This VB.Net and MySQL Tutorial We Will See How To Calculate and Display the Percentage Values From a MySQL Database Table Using Visual Basic.Net Programming Language And Visual Studio Editor.

- To Learn More Watch The Video Tutorial Below. 


Project Source Code:

Imports MySql.Data.MySqlClient

Public Class calc_percent_form

    ' create the connection with mysql database
    Dim connection As New MySqlConnection("datasource=localhost;port=3306;username=root;password=;database=vbnet_student_db")

    Private Sub calc_percent_form_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Dim totalStd As Integer = Convert.ToInt32(totalStudents())
        Dim totalMaleStd As Integer = Convert.ToInt32(totalMaleStudents())
        Dim totalFemaleStd As Integer = Convert.ToInt32(totalFemaleStudents())

        ' the % formula
        ' (male students * 100) / totale students
        ' (female students * 100) / totale students

        Dim maleStd_p As Double = (totalMaleStd * 100) / totalStd
        Dim femaleStd_p As Double = (totalFemaleStd * 100) / totalStd

        lbl_total_students.Text = totalStd.ToString()
        lbl_total_Male_Students.Text = maleStd_p.ToString("0.00") & "%"
        lbl_total_Female_Students.Text = femaleStd_p.ToString("0.00") & "%"


    End Sub


    'create a function to execute count queries
    Function execQuery(ByVal query As String) As String

        Dim command As New MySqlCommand(query, connection)

        ' open connection
        If connection.State = ConnectionState.Closed Then
            connection.Open()
        End If

        Return command.ExecuteScalar.ToString()

        ' close connection
        If connection.State = ConnectionState.Open Then
            connection.Close()
        End If


    End Function


    ' create a function to return total students
    Function totalStudents() As String

        Return execQuery("SELECT COUNT(*) FROM `student`")

    End Function

    ' create a function to return total MALE students
    Function totalMaleStudents() As String

        Return execQuery("SELECT COUNT(*) FROM `student` WHERE gender = 'MALE'")

    End Function

    ' create a function to return total FEMALE students
    Function totalFemaleStudents() As String

        Return execQuery("SELECT COUNT(*) FROM `student` WHERE gender = 'FEMALE'")

    End Function


End Class  
   


///////////////OUTPUT:



How To Calculate Percentage From MySQL Using Vbnet



JAVA SlideShow From MySQL Database

How To Make Images Slider From MySQL Database In Java NetBeans

JAVA Images Slider From MySQL Database



In this Java Tutorial we will see How To Create an Images SlideShow with Images From MySQL Database Table Using Java NetBeans and  .
and to do that we make two button to navigate to the next and previous image.



WATCH THIS JAVA TUTORIAL


Project Source Code:


package javatutorials;

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
import java.awt.Image;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;

/**
 *
 * @author 1BestCsharp
 */
public class Images_Slider_From_MySQL_Database extends javax.swing.JFrame {

    /**
     * Creates new form Images_Slider_From_MySQL_Database
     */
    
    // image index variable
    Integer imgIndex = 0;
    
    public Images_Slider_From_MySQL_Database() {
        initComponents();
        
        showImage(imgIndex);
    }

    
    // create a function to connect with mysql database
    public Connection createConnection(){
        
        Connection myConnection = null;
        
        MysqlDataSource datasource = new MysqlDataSource();
        
        datasource.setServerName("localhost");
        datasource.setPortNumber(3306);
        datasource.setUser("root");
        datasource.setPassword("");
        datasource.setDatabaseName("db_images");
        
        try {
            myConnection = datasource.getConnection();
        } catch (SQLException ex) {
            Logger.getLogger(Images_Slider_From_MySQL_Database.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        return myConnection;
    }
    
    
    // create a function to populate an arraylist with images from mysql
    public ArrayList<byte[]> getImagesList(){
        
        ArrayList<byte[]> imgList = new ArrayList<>();
        
        Connection con = createConnection();
        
        Statement st;
        ResultSet rs;
        
        try {
            
            st = con.createStatement();
            rs = st.executeQuery("SELECT Image FROM `myimages`");
            
            while(rs.next()){
                
               imgList.add(rs.getBytes("Image")); 
               
            }
            
        } catch (SQLException ex) {
            Logger.getLogger(Images_Slider_From_MySQL_Database.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        return imgList;
    }
    
    
    // create a function to show and resize the image to fit the JLabel
    public void showImage(Integer index){
        
        Image img = new ImageIcon(getImagesList().get(index)).getImage().getScaledInstance(jLabel1.getWidth(), jLabel1.getHeight(), Image.SCALE_SMOOTH);
        jLabel1.setIcon(new ImageIcon(img));
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jButton_Next_ = new javax.swing.JButton();
        jButton_Previous_ = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBackground(new java.awt.Color(204, 204, 204));

        jLabel1.setBackground(new java.awt.Color(255, 255, 255));
        jLabel1.setOpaque(true);

        jButton_Next_.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jButton_Next_.setText("==>");
        jButton_Next_.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_Next_ActionPerformed(evt);
            }
        });

        jButton_Previous_.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jButton_Previous_.setText("<==");
        jButton_Previous_.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_Previous_ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(6, 6, 6)
                .addComponent(jButton_Previous_, javax.swing.GroupLayout.DEFAULT_SIZE, 83, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 585, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton_Next_, javax.swing.GroupLayout.DEFAULT_SIZE, 83, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(32, 32, 32)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 364, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(193, 193, 193)
                        .addComponent(jButton_Next_, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(29, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(jButton_Previous_, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(184, 184, 184))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>                        

    
// Button Next 
private void jButton_Next_ActionPerformed(java.awt.event.ActionEvent evt) {                                              
        
        imgIndex++;
        
        if(imgIndex >= getImagesList().size()){
            
            imgIndex = getImagesList().size() - 1;
            
        }
        
        showImage(imgIndex);
        
    }                                             

    
// Button Previous
private void jButton_Previous_ActionPerformed(java.awt.event.ActionEvent evt) {                                                  
        
        imgIndex--;
        
        if(imgIndex < 0){
            
            imgIndex = 0;
            
        }
        
        showImage(imgIndex);
        
    }                                                 

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Images_Slider_From_MySQL_Database.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Images_Slider_From_MySQL_Database.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Images_Slider_From_MySQL_Database.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Images_Slider_From_MySQL_Database.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Images_Slider_From_MySQL_Database().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JButton jButton_Next_;
    private javax.swing.JButton jButton_Previous_;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration                   
}
    

OutPut:

JAVA Images Slider From MySQL Database



C# Images Slider From MySQL Database

How To Make Images SlideShow From MySQL Database Using C#

C# Images Slider From Database


In This C# Tutorial we will See How To Make an Image SlideShow With Images From MySQL Database Table in C# And Visual Studio Editor .

we need to create two buttons:
1-  "NEXT" => go to the next image in the mysql database table
2- "PREVIOUS" => go to the previous image in the mysql database table



WATCH THIS C# TUTORIAL


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_Tutorials
{
    public partial class Images_SlideShow_From_MySQL : Form
    {
        public Images_SlideShow_From_MySQL()
        {
            InitializeComponent();
        }

// the mysql connection
        MySqlConnection connection = new MySqlConnection("datasource=localhost;port=3306;Initial Catalog='student_db';username=root;password=");

        // create a datatable
        DataTable table = new DataTable();

        // int variable to get the row index
        int rowIndex;

        // the form load
        private void Images_SlideShow_From_MySQL_Load(object sender, EventArgs e)
        {

            MySqlCommand command = new MySqlCommand("SELECT picture FROM `student`", connection);

            MySqlDataAdapter adapter = new MySqlDataAdapter(command);

            adapter.Fill(table);

            rowIndex = 0;

            showImage();

        }


        // create a method to display image depending on the rowindex value
        public void showImage()
        {
            Byte[] imgByte = (Byte[])table.Rows[rowIndex][0];

            MemoryStream ms = new MemoryStream(imgByte);

            pictureBox1.Image = Image.FromStream(ms);

        }


        // button next image
        private void button_Next_Click(object sender, EventArgs e)
        {
            if(rowIndex < table.Rows.Count -1)
            {
                rowIndex++;
                showImage();
            }
            
        }

      
       // button previous
        private void button_Previous_Click(object sender, EventArgs e)
        {
            if (rowIndex >= 1)
            {
                rowIndex--;
                showImage();
            }
            
        }
    }
}



OUTPUT:


images slider in c#