VB.NET 2019 and SQL Server (V1) Perform SMART CRUD Operations with SEARCH (Windows Forms Source Code)


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

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

👨‍🏫 How to connect SQL Server 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

YouTube : (Original Version)
▶️ https://youtu.be/V7zZ92qS7Bg

YouTube : Edited Version (Part 1/2)
▶️ https://youtu.be/96zLDIS4Z10

YouTube : Edited Version (Part 2/2)
▶️ https://youtu.be/4wQINvVO5Js

[-📍-] 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]

🎯 Souce Code: http://bit.ly/35G4jHr

#BEGIN

Module: MOD_SMART_CRUD.vb

Option Explicit On
Option Strict On

Imports System.Data.SqlClient

Module MOD_SMART_CRUD

    Public Constring As String = "Data Source=TANIN-SANGNGAM\SQLEXPRESS;Initial Catalog=VB_SMART_CRUD;Integrated Security=True"
    Public Con As New SqlConnection(Constring)
    Public Cmd As SqlCommand
    Public SQL As String = String.Empty

    Public Function PerformCRUD(Com As SqlCommand) As DataTable

        Dim da As SqlDataAdapter
        Dim dt As New DataTable()

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

        Return dt

    End Function

End Module

Form: CRUD_FORM.vb

Option Explicit On
Option Strict On

Imports System.Data.SqlClient

Public Class CRUD_FORM

    Private ID As String = ""

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

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

    Private Sub AddParameters(str As String)

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

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

    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 TB_SMART_CRUD " &
              "WHERE [FIRST_NAME] + ' ' + [LAST_NAME] LIKE '%' + @keyword + '%'"

        Cmd = New SqlCommand(SQL, Con)
        Cmd.Parameters.Clear()
        Cmd.Parameters.AddWithValue("keyword", keyword)

        Dim dt As DataTable = PerformCRUD(Cmd)

        If dt.Rows.Count > 0 Then
            ' MsgBox("Number of rows: " & dt.Rows.Count.ToString())
        End If

        With DataGridView1

            .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 = 70
            .Columns(1).Width = 150
            .Columns(2).Width = 150
            .Columns(3).Width = 200
            .Columns(4).Width = 90

        End With

    End Sub

    Private Sub ResetMe()

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

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

        UpdateButton.Text = "Update ()"
        DeleteButton.Text = "Delete ()"

    End Sub

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

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

        SQL = "INSERT INTO TB_SMART_CRUD(FIRST_NAME, LAST_NAME, GENDER) VALUES(@FirstName, @LastName, @Gender)"

        Execute(SQL, "Insert")

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

        LoadData()

        ResetMe()

    End Sub

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

        Try

            Dim dgv As DataGridView = DataGridView1

            If e.RowIndex <> -1 Then

                Me.ID = Convert.ToString(dgv.CurrentRow.Cells(0).Value)
                UpdateButton.Text = "Update (" & Me.ID & ")"
                DeleteButton.Text = "Delete (" & Me.ID & ")"

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

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

            End If

        Catch ex As Exception

        End Try

    End Sub

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

        If DataGridView1.Rows.Count = 0 Then
            MsgBox(DataGridView1.Rows.Count.ToString() & " No rows found.",
                   MsgBoxStyle.OkOnly Or MsgBoxStyle.Information, "Update Data : iBasskung Tutorial")
            Exit Sub
        End If

        If UpdateButton.Text.Equals("Update ()") Then
            MessageBox.Show("Please select an item from the list.",
                        "Update Date : iBasskung Tutorial", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Exit Sub
        End If

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

        Try

            SQL = "UPDATE TB_SMART_CRUD SET FIRST_NAME = @FirstName, LAST_NAME = @LastName, GENDER = @Gender WHERE AUTO_ID = @ID"

            Execute(SQL, "Update")

            MsgBox("The record has been updated!",
                   MsgBoxStyle.OkOnly Or MsgBoxStyle.Information, "Update Data : iBasskung Tutorial")

            LoadData()

            ResetMe()

        Catch ex As Exception

        End Try

    End Sub

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

        If DataGridView1.Rows.Count = 0 Then
            MsgBox(DataGridView1.Rows.Count.ToString() & " No rows found.",
                   MsgBoxStyle.OkOnly Or MsgBoxStyle.Information, "Delete Data : iBasskung Tutorial")
            Exit Sub
        End If

        If DeleteButton.Text.Equals("Delete ()") Then
            MessageBox.Show("Please select an item from the list.",
                        "Delete Date : iBasskung Tutorial", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Exit Sub
        End If

        Try

            SQL = "DELETE FROM TB_SMART_CRUD WHERE AUTO_ID = @ID"

            Execute(SQL, "Delete")

            MsgBox("The record has been deleted!",
                   MsgBoxStyle.OkOnly Or MsgBoxStyle.Information, "Delete Data : iBasskung Tutorial")


            LoadData()

            ResetMe()

        Catch ex As Exception

        End Try

    End Sub

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

        Try

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

            ResetMe()

            ' Clear
            KeywordTextBox.Text = ""

        Catch ex As Exception
            MsgBox("An error occurred: " & ex.Message.ToString(), MsgBoxStyle.OkOnly Or MsgBoxStyle.Critical, "Search Error")
        End Try

    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:
📍 https://www.facebook.com/CodeAMinute
📍 https://www.facebook.com/IbasskungTutorial
📍 https://www.facebook.com/codewithibasskung

📺 YouTube:
📍 https://www.youtube.com/c/iBasskung

📺 Udemy (Online Course):
📍 https://www.udemy.com/vbnet-crystal-reports

📺 Twitter:
📍 https://twitter.com/#!/IBasskung

📺 Blogger:
📍 https://codeaminute.blogspot.com
📍 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 #SQLServer #CRUDOperation

Comments