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



VB.Net And MySQL DataBase - INSERT UPDATE DELETE SEARCH

VB.NET - How To Insert Update Search Delete Data From MySQL Using Visual Basic.Net

vb.net and mysql add edit remove find

In This VB.Net Tutorial  We Will See How To: 
 - Insert Data Into MySQL Database Table.
 - Update Data From MySQL Database Table With A Specific ID.
 Delete Data From MySQL Database Table With A Specific ID.
 - Search Data In MySQL Database With A Specific ID And Display The Information Into TextBoxes And DateTimePicker ( if data exists )
Using Visual Basic.Net  Programming Language And Visual Studio Editor.


Part 1


Part 2


Project Source Code:

Imports MySql.Data.MySqlClient

Public Class Insert_Update_Delete_Search

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

    ' button find 
    Private Sub ButtonSearch_Click(sender As Object, e As EventArgs) Handles ButtonSearch.Click

        Dim search_command As New MySqlCommand("SELECT * FROM `student` WHERE `Id` = @id", connection)

        search_command.Parameters.Add("@id", MySqlDbType.Int64).Value = TextBox1.Text

        Dim adapter As New MySqlDataAdapter(search_command)

        Dim table As New DataTable()

        Try

            adapter.Fill(table)

            If table.Rows.Count > 0 Then

                TextBox2.Text = table(0)(1)
                TextBox3.Text = table(0)(2)
                DateTimePicker1.Value = table(0)(3)

            Else

                TextBox2.Text = ""
                TextBox3.Text = ""
                DateTimePicker1.Value = Now()
                MessageBox.Show("No Data Found")

            End If

        Catch ex As Exception

            MessageBox.Show("ERROR")

        End Try

    End Sub

      ' function to execute the insert update delete commands 
    Function execCommand(ByVal cmd As MySqlCommand) As Boolean

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

        Try
            If cmd.ExecuteNonQuery() = 1 Then
                Return True

            Else
                Return False
            End If
        Catch ex As Exception

            MessageBox.Show("ERROR")
            Return False

        End Try

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

    End Function

    ' button add 
    Private Sub ButtonInsert_Click(sender As Object, e As EventArgs) Handles ButtonInsert.Click

        Dim insert_command As New MySqlCommand("INSERT INTO `student`(`FullName`, `Address`, `BirthDate`) VALUES (@fln,@adds,@brd)", connection)
        insert_command.Parameters.Add("@fln", MySqlDbType.VarChar).Value = TextBox2.Text
        insert_command.Parameters.Add("@adds", MySqlDbType.VarChar).Value = TextBox3.Text
        insert_command.Parameters.Add("@brd", MySqlDbType.Date).Value = DateTimePicker1.Value

        If execCommand(insert_command) Then
            MessageBox.Show("Data Inserted")

        Else
            MessageBox.Show("Data NOT Inserted")
        End If

    End Sub

    ' button edit 
    Private Sub ButtonUpdate_Click(sender As Object, e As EventArgs) Handles ButtonUpdate.Click

        Dim update_command As New MySqlCommand("UPDATE `student` SET `FullName`=@fln,`Address`=@adds,`BirthDate`=@brd WHERE `Id` = @id", connection)
        update_command.Parameters.Add("@id", MySqlDbType.Int64).Value = TextBox1.Text
        update_command.Parameters.Add("@fln", MySqlDbType.VarChar).Value = TextBox2.Text
        update_command.Parameters.Add("@adds", MySqlDbType.VarChar).Value = TextBox3.Text
        update_command.Parameters.Add("@brd", MySqlDbType.Date).Value = DateTimePicker1.Value

        If execCommand(update_command) Then
            MessageBox.Show("Data Updated")

        Else
            MessageBox.Show("Data NOT Updated")
        End If

    End Sub

    ' button remove 
    Private Sub ButtonDelete_Click(sender As Object, e As EventArgs) Handles ButtonDelete.Click

        Dim delete_command As New MySqlCommand("DELETE FROM `student` WHERE `Id` = @id", connection)
        delete_command.Parameters.Add("@id", MySqlDbType.Int64).Value = TextBox1.Text

        If execCommand(delete_command) Then
            MessageBox.Show("Data Deleted")

        Else
            MessageBox.Show("Data NOT Deleted")
        End If

    End Sub
End Class

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

Add Edit Find Remove Data From MySQL Database In Visual Basic.Net



VB.Net And MySQL Search

How To Search Data In MySQL Database Using VbNet

vb.net search in database

In This VB.Net Tutorial  We Will See How To Get The ID From TextBox And Search In Database Data With This Specific ID And Display The Other Information From MySQL DataBase Table Using 2 Way (MySqlDataReader, MySqlDataAdapter + DataTable) In Visual Basic.Net  Programming Language And Visual Studio Editor.


Project Source Code:

Imports MySql.Data.MySqlClient

Public Class Search_Data_In_MySQL

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

    Private Sub ButtonSearch_Click(sender As Object, e As EventArgs) Handles ButtonSearch.Click

        ' using dataReader 

        'Dim command As New MySqlCommand("SELECT * FROM `student` WHERE `Id` = @id", connection)

        'command.Parameters.Add("@id", MySqlDbType.Int64).Value = TextBox1.Text

        'Dim reader As MySqlDataReader

        'connection.Open()

        'reader = command.ExecuteReader()

        'If reader.Read() Then

        '    TextBox2.Text = reader(1)
        '    TextBox3.Text = reader(2)
        '    DateTimePicker1.Value = reader(3)

        'End If

        'connection.Close()

        '---------------------------------------

        ' using dataTable 

        Dim command As New MySqlCommand("SELECT * FROM `student` WHERE `Id` = @id", connection)

        Command.Parameters.Add("@id", MySqlDbType.Int64).Value = TextBox1.Text

        Dim adapter As New MySqlDataAdapter(command)

        Dim table As New DataTable()

        Try

            adapter.Fill(table)

            If table.Rows.Count > 0 Then

                'TextBox1.Text = table(0)(0)
                TextBox2.Text = table(0)(1)
                TextBox3.Text = table(0)(2)

                DateTimePicker1.Value = table(0)(3)

            Else

                TextBox2.Text = ""
                TextBox3.Text = ""

                DateTimePicker1.Value = Now()

            End If

        Catch ex As Exception

            MessageBox.Show(ex.Message.ToString())

        End Try


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

vbnet search data in mysql database




VB.Net Delete MySQL Data

How To Remove Data From MySQL Database Using VbNet

VB.Ne Andt MySQL Delete

In This VB.Net Tutorial  We Will See How To Delete The Selected Data From MySQL DataBase Table Using TextBox For The ID  To Just Remove The Data With This Specific ID Using MySqlCommand With Parameters In Visual Basic.Net  Programming Language And Visual Studio Editor.


Project Source Code:

Imports MySql.Data.MySqlClient

Public Class Delete_MySQL_Data

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

    Private Sub ButtonDelete_Click(sender As Object, e As EventArgs) Handles ButtonDelete.Click

        Dim command As New MySqlCommand("DELETE FROM `student` WHERE `Id` = @id", connection)

        command.Parameters.Add("@id", MySqlDbType.Int64).Value = TextBox1.Text

        connection.Open()

        Try

            If command.ExecuteNonQuery() = 1 Then

                MessageBox.Show("Data Deleted")

            Else

                MessageBox.Show("Error")

            End If

        Catch ex As Exception

            MessageBox.Show("Something Wrong")

        End Try


        connection.Close()

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

delete data from mysql database using vb.net




VB.Net Update MySQL Data

How To Edit Data In MySQL Database Using VbNet

VB.Net Update MySQL Database Data

In This VB.Net Tutorial  We Will See How To Get Data From TextBoxes And DateTimePicker  And Update The Selected Data From MySQL DataBase Table Using ID To Just Edit The Data With This Specific ID Using MySqlCommand With Parameters In Visual Basic.Net  Programming Language And Visual Studio Editor.


Project Source Code:

Imports MySql.Data.MySqlClient

Public Class Update_MySQL_Data

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

    Private Sub ButtonInsert_Click(sender As Object, e As EventArgs) Handles ButtonInsert.Click

        Dim command As New MySqlCommand("UPDATE `student` SET `FullName`=@fn,`Address`=@adds,`BirthDate`=@brd WHERE `Id` =@id", connection)

        command.Parameters.Add("@id", MySqlDbType.Int64).Value = TextBox1.Text
        command.Parameters.Add("@fn", MySqlDbType.VarChar).Value = TextBox2.Text
        command.Parameters.Add("@adds", MySqlDbType.VarChar).Value = TextBox3.Text
        command.Parameters.Add("@brd", MySqlDbType.Date).Value = DateTimePicker1.Value

        connection.Open()

        If command.ExecuteNonQuery() = 1 Then

            MessageBox.Show("Data Updated")

        Else

            MessageBox.Show("ERROR")

        End If

        connection.Close()

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

Update MySQL Data In VBnet