VB.NET 2019 and Access Database Perform SMART CRUD Operations with SEARCH (Windows Forms Source Code)


Microsoft Visual Studio 2019 : Visual Basic .NET (VB.NET and Microsoft Access 2016 Tutorial).
👨‍🏫 How to Perform SMART CRUD (Create Read Update & Delete) Operations with Search functionality.

🎓 Master Visual Basic .NET and Access Database By Building the Point Of Sale System (POS).
📲 Enroll Now: https://bit.ly/2WcbRhX

👨‍🏫 How to connect Access database using VB.NET
In computer programming, create, read, update, and delete (CRUD) are the four basic functions of persistent storage. Alternate words are sometimes used when defining the four basic functions of CRUD, such as retrieve instead of read, modify instead of update, or destroy instead of delete.
Read more: Wikipedia

Screenshot 1

Screenshot 2

YouTube Part 1/2

YouTube Part 2/2

[-📍-] Recommended Videos [-📍-]

🚀 4K | How to Download and Install Visual Studio 2019, SQL Server 2017 and SQL Server Management Studio (SSMS).
📺 https://youtu.be/ZA19qSiPcOE

🚀 4K | How to Download and Install PostgreSQL on Windows 10 and NpgSQL - ADO.NET Data Provider for PostgreSQL.
📺 https://youtu.be/KCxWG2g22yo

🚀 4K | How to download and install XAMPP for Windows 10 and MySQL Connector/NET.
📺 https://youtu.be/yHYyMMlYRjk

[-📍-] Bonus Video Tutorials [-📍-]

-- Microsoft SQL Server --
Microsoft SQL Server is a relational database management system developed by Microsoft. As a database server, it is a software product with the primary function of storing and retrieving data as requested by other software applications—which may run either on the same computer or on another computer across a network. Wikipedia

🚀 4K | VB.NET and SQL Server Tutorial | Perform SMART CRUD (Create Read Update & Delete) Operations with Search functionality.
📺 Version 1: https://youtu.be/V7zZ92qS7Bg
📺 Version 2: https://youtu.be/jIyGTcccM94

🚀 4K | C# and SQL Server Tutorial | Perform SMART CRUD (Create Read Update & Delete) Operations with Search functionality.
📺 Version 1: https://youtu.be/ZA4wr2DW88E
📺 Version 2: https://youtu.be/i_yQHRbFBAA

-- PostgreSQL --
PostgreSQL, also known as Postgres, is a free and open-source relational database management system emphasizing extensibility and technical standards compliance. It is designed to handle a range of workloads, from single machines to data warehouses or Web services with many concurrent users. Wikipedia

🚀 4K | VB.NET and PostgreSQL Tutorial | Perform SMART CRUD (Create Read Update & Delete) Operations with Search functionality.
📺 https://youtu.be/kqyeaTWol9k
🚀 4K | C# and PostgreSQL Tutorial | Perform SMART CRUD (Create Read Update & Delete) Operations with Search functionality.
📺 https://youtu.be/SnpW2hAuTmk

-- MySQL --
MySQL is an open-source relational database management system. Its name is a combination of "My", the name of co-founder Michael Widenius's daughter, and "SQL", the abbreviation for Structured Query Language. Wikipedia

🚀 4K | VB.NET and MySQL Tutorial | Perform SMART CRUD (Create Read Update & Delete) Operations with Search functionality.
📺 https://youtu.be/J2e9q9CgxVI
🚀 4K | C# and MySQL Tutorial | Perform SMART CRUD (Create Read Update & Delete) Operations with Search functionality.
📺 https://youtu.be/tvd6tnQcDGA

-- Microsoft Access --
Microsoft Access is a database management system from Microsoft that combines the relational Microsoft Jet Database Engine with a graphical user interface and software-development tools. It is a member of the Microsoft Office suite of applications, included in the Professional and higher editions or sold separately. Wikipedia

🚀 Full-HD | VB.NET and Access Database Tutorial | Perform SMART CRUD (Create Read Update & Delete) Operations with Search functionality.
📺 Part 1/2: https://youtu.be/LfHSZ7vLwyU
📺 Part 2/2: https://youtu.be/PMZXbvQ5X5Y

🚀 Full-HD | C# and Access Database Tutorial | Perform SMART CRUD (Create Read Update & Delete) Operations with Search functionality.
📺 Part 1/2: https://youtu.be/TNOdAwOo4Kk
📺 Part 2/2: https://youtu.be/wonsL3PpOY4

[FREE SOURCE CODE by iBASSKUNG]

#BEGIN

Module: AccessDb_Connection.vb

Option Explicit On
Option Strict On

Imports System.Data
Imports System.Data.OleDb

Module AccessDb_Connection

    Public Function GetConnectionString() As String
        Dim strCon As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath
        strCon &= "\VB_SMART_CRUD.accdb;Persist Security Info=False;"
        Return strCon
    End Function

    Public Con As New OleDbConnection(GetConnectionString())
    Public Cmd As OleDbCommand
    Public SQL As String = String.Empty

    Public Function PerformCRUD(Com As OleDbCommand) As DataTable

        Dim da As OleDbDataAdapter
        Dim dt As New DataTable()

        Try

            da = New OleDbDataAdapter
            da.SelectCommand = Com
            da.Fill(dt)

            Return dt

        Catch ex As Exception
            MessageBox.Show("An error occurred: " & ex.Message, "Perform CRUD OPERATIONS Failed. : iBasskung Tutorial",
                 MessageBoxButtons.OK, MessageBoxIcon.Error)
            dt = Nothing
        End Try

        Return dt

    End Function


End Module

Form: Form1.vb

Option Explicit On
Option Strict On

Imports System.Data.OleDb

Public Class Form1

    Private ID As String = ""
    Private intRow As Integer = 0

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ResetMe()
        LoadData()
    End Sub

    Private Sub ResetMe()

        Me.ID = ""

        FirstNameTextBox.Text = ""
        LastNameTextBox.Text = ""

        If GenderComboBox.Items.Count > 0 Then
            GenderComboBox.SelectedIndex = 0
        End If

        UpdateButton.Text = "UPDATE ()"
        DeleteButton.Text = "DELETE ()"

        With KeywordTextBox
            .Clear()
            .Select()
        End With

    End Sub

    Private Sub Execute(MySQL As String, Optional Parameter As String = "")
        Cmd = New OleDbCommand(MySQL, Con)
        AddParameters(Parameter)
        PerformCRUD(Cmd)
    End Sub

    Private Sub AddParameters(str As String)

        Cmd.Parameters.Clear()

        If str = "Delete" And Not String.IsNullOrEmpty(Me.ID) Then
            Cmd.Parameters.AddWithValue("ID", Me.ID)
        End If

        Cmd.Parameters.AddWithValue("FirstName", FirstNameTextBox.Text.Trim())
        Cmd.Parameters.AddWithValue("LastName", LastNameTextBox.Text.Trim())
        Cmd.Parameters.AddWithValue("Gender", GenderComboBox.SelectedItem.ToString())

        If str = "Update" And Not String.IsNullOrEmpty(Me.ID) Then
            Cmd.Parameters.AddWithValue("ID", Me.ID)
        End If

    End Sub

    Private Sub InsertButton_Click(sender As Object, e As EventArgs) Handles InsertButton.Click

        If String.IsNullOrEmpty(Me.FirstNameTextBox.Text.Trim()) Or
           String.IsNullOrEmpty(Me.LastNameTextBox.Text.Trim()) Then
            MessageBox.Show("Please input first name and last name.", "Access : Insert Data : iBasskung Tutorial",
                            MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Exit Sub
        End If

        SQL = "INSERT INTO TBL_SMART_CRUD(First_Name, Last_Name, Gender) VALUES(@FirstName, @LastName, @Gender)"

        Execute(SQL, "Insert")

        MessageBox.Show("The record has been saved.", "Access : Insert Data : iBasskung Tutorial",
                            MessageBoxButtons.OK, MessageBoxIcon.Information)

        LoadData()

        ResetMe()

    End Sub

    Private Sub LoadData(Optional keyword As String = "")

        SQL = "SELECT Auto_ID, First_Name, Last_Name, [First_Name] + ' ' + [Last_Name] AS Full_Name, Gender FROM TBL_SMART_CRUD " &
              "WHERE [First_Name] + ' ' + [Last_Name] LIKE @keyword1 OR Gender = @keyword2 ORDER BY Auto_ID ASC"

        Dim strKeyword As String = String.Format("%{0}%", keyword)

        Cmd = New OleDbCommand(SQL, Con)
        Cmd.Parameters.Clear()
        Cmd.Parameters.AddWithValue("keyword1", strKeyword)
        Cmd.Parameters.AddWithValue("keyword2", keyword)

        Dim dt As DataTable = PerformCRUD(Cmd)

        If dt.Rows.Count > 0 Then
            intRow = Convert.ToInt32(dt.Rows.Count.ToString())
        Else
            intRow = 0
        End If

        ToolStripStatusLabel1.Text = "Number of row(s): " & intRow.ToString()

        With DataGridView1

            .MultiSelect = False
            .SelectionMode = DataGridViewSelectionMode.FullRowSelect
            .AutoGenerateColumns = True

            .DataSource = dt

            .Columns(0).HeaderText = "ID"
            .Columns(1).HeaderText = "First Name"
            .Columns(2).HeaderText = "Last Name"
            .Columns(3).HeaderText = "Full Name"
            .Columns(4).HeaderText = "Gender"

            .Columns(0).Width = 85
            .Columns(1).Width = 170
            .Columns(2).Width = 170
            .Columns(3).Width = 220
            .Columns(4).Width = 100

        End With

    End Sub

    Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick

        Dim dgv As DataGridView = DataGridView1

        If e.RowIndex <> -1 Then

            Me.ID = Convert.ToString(dgv.CurrentRow.Cells(0).Value).Trim()
            UpdateButton.Text = "UPDATE (" & Me.ID & ")"
            DeleteButton.Text = "DELETE (" & Me.ID & ")"

            FirstNameTextBox.Text = Convert.ToString(dgv.CurrentRow.Cells(1).Value).Trim()
            LastNameTextBox.Text = Convert.ToString(dgv.CurrentRow.Cells(2).Value).Trim()

            GenderComboBox.SelectedItem = Convert.ToString(dgv.CurrentRow.Cells(4).Value).Trim()

        End If

    End Sub

    Private Sub UpdateButton_Click(sender As Object, e As EventArgs) Handles UpdateButton.Click

        If DataGridView1.Rows.Count = 0 Then
            Exit Sub
        End If

        If String.IsNullOrEmpty(Me.ID) Then
            MessageBox.Show("Please select an item from the list.", "Access : Update Data : iBasskung Tutorial",
                            MessageBoxButtons.OK, MessageBoxIcon.Information)
            Exit Sub
        End If

        If String.IsNullOrEmpty(Me.FirstNameTextBox.Text.Trim()) Or
            String.IsNullOrEmpty(Me.LastNameTextBox.Text.Trim()) Then
            MessageBox.Show("Please input first name and last name.", "Access : Update Data : iBasskung Tutorial",
                            MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Exit Sub
        End If

        SQL = "UPDATE TBL_SMART_CRUD SET First_Name = @FirstName, Last_Name = @LastName, Gender = @Gender WHERE Auto_ID = @ID"

        Execute(SQL, "Update")

        MessageBox.Show("The record has been saved.", "Access : Update Data : iBasskung Tutorial",
                            MessageBoxButtons.OK, MessageBoxIcon.Information)

        LoadData()

        ResetMe()

    End Sub

    Private Sub DeleteButton_Click(sender As Object, e As EventArgs) Handles DeleteButton.Click

        If DataGridView1.Rows.Count = 0 Then
            Exit Sub
        End If

        If String.IsNullOrEmpty(Me.ID) Then
            MessageBox.Show("Please select an item from the list.", "Access : Delete Data : iBasskung Tutorial",
                            MessageBoxButtons.OK, MessageBoxIcon.Information)
            Exit Sub
        End If

        If MessageBox.Show("Do you want to permaneltly delete the selectd record?",
                           "Access : Delete Data : iBasskung Tutorial",
                           MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then

            SQL = "DELETE * FROM TBL_SMART_CRUD WHERE Auto_ID = @ID"

            Execute(SQL, "Delete")

            MessageBox.Show("The record has been saved.", "Access : Delete Data : iBasskung Tutorial",
                                MessageBoxButtons.OK, MessageBoxIcon.Information)

            LoadData()

            ResetMe()

        End If

    End Sub

    Private Sub SearchButton_Click(sender As Object, e As EventArgs) Handles SearchButton.Click

        If Not String.IsNullOrEmpty(KeywordTextBox.Text.Trim()) Then
            LoadData(Me.KeywordTextBox.Text.Trim())
        Else
            LoadData()
        End If

        ResetMe()

    End Sub

End Class

#END

Follow me around
✔ Want to get updates on new courses or other cool free stuff? Just follow me on social media if that's your thing!

📺 Pages:

📺 YouTube:

📺 Udemy (Online Course):

📺 Twitter:

📺 Blogger:
📍 http://bit.ly/2wjuwvs

💯 THANK YOU SO MUCH! 💯

Tags: visual studio 2019, visual basic 2019, vb.net, vb.net tutorial for beginners visual studio 2019, visual basic, vb, visual studio 2019 visual basic tutorial, visual studio 2019 tutorial, how to use visual studio 2019, visual basic tutorial 2019, access, visual studio

#VBDotNET #VisualBasicDotNET #AccessDatabase #CRUDOperation 

Comments