VB.Net And MySQL Search Data Between 2 Dates

How To Search Data In MySQL Database Between Two Dates Using VbNet

VBNet And MySQL Database Search Data Between Two Dates

In This VB.Net Tutorial  We Will See How To Get Data Between Two Date From MySQL Database Table Using DateTimePicker And Display The Selected Data Into A DataGridView  In Visual Basic.Net  Programming Language And Visual Studio Editor.


Project Source Code:

Imports MySql.Data.MySqlClient

Public Class Search_Data_In_MySQL_Between_2_Date

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

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

        Dim table As New DataTable()
        Dim adapter As New MySqlDataAdapter("SELECT * FROM student", connection)

        adapter.Fill(table)

        DataGridView1.DataSource = table

    End Sub

    ' button search 
    Private Sub ButtonGO_Click(sender As Object, e As EventArgs) Handles ButtonGO.Click

        Dim table As New DataTable()
        Dim command As New MySqlCommand("SELECT * FROM `student` WHERE `BirthDate` BETWEEN @d1 AND @d2", connection)

        command.Parameters.Add("@d1", MySqlDbType.Date).Value = DateTimePickerD1.Value
        command.Parameters.Add("@d2", MySqlDbType.Date).Value = DateTimePickerD2.Value

        Dim adapter As New MySqlDataAdapter(command)

        adapter.Fill(table)

        DataGridView1.DataSource = table

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

MySQL Database Search Data Between 2 Dates In VB.Net



Share this

Related Posts

Previous
Next Post »