VB.NET 2019 and SQL Server (V2) 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 2).

🎓 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


[-📍-] 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/2SerdBU

#BEGIN

Form: Form1.vb

Option Explicit On
Option Strict On

Imports System.Data.SqlClient

Public Class Form1

    Private ConString As String = "Data Source=TANIN-SANGNGAM\SQLEXPRESS;Initial Catalog=VB_SMART_CRUD;Integrated Security=True"
    Private SQL As String = String.Empty
    Private ID As String = ""

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        LoadData()
        ResetMe()
    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 LoadData()

        SQL = "SELECT AUTO_ID AS ID, FIRST_NAME AS [FIrst Name], LAST_NAME AS [Last Name], [FIRST_NAME] + ' ' + [LAST_NAME] AS [Full Name], " &
              "GENDER AS [Gender] FROM TB_SMART_CRUD WHERE ([FIRST_NAME] + ' ' + [LAST_NAME]) LIKE '%' + @keyword + '%'"

        Dim dt As DataTable = PerformCRUD(SQL, "Select")

        With DataGridView1

            .DataSource = dt

            .Columns(0).Width = 80
            .Columns(1).Width = 180
            .Columns(2).Width = 180
            .Columns(3).Width = 220
            .Columns(4).Width = 145

        End With

    End Sub

    Function PerformCRUD(MySQL As String, Optional str As String = "") As DataTable

        Using Conn As New SqlConnection(ConString)

            Using Comm As New SqlCommand(MySQL, Conn)

                Comm.Parameters.Clear()

                If str = "Select" Then
                    Comm.Parameters.AddWithValue("keyword", KeywordTextBox.Text.Trim())
                End If

                If str = "Insert" Or str = "Update" Then
                    Comm.Parameters.AddWithValue("FirstName", FirstNameTextBox.Text.Trim())
                    Comm.Parameters.AddWithValue("LastName", LastNameTextBox.Text.Trim())
                    Comm.Parameters.AddWithValue("Gender", GenderComboBox.SelectedItem.ToString())
                End If

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

                Dim da As SqlDataAdapter
                Dim dt As New DataTable

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

                Return dt

            End Using

        End Using

    End Function

    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 Data : iBasskung Tutorial", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Exit Sub
        End If

        Try

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

            PerformCRUD(SQL, "Insert")

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

            LoadData()

            ResetMe()

        Catch ex As Exception

        End Try

    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 & ")"

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

                Me.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.")
            Exit Sub
        End If

        If UpdateButton.Text.Equals("Update ()") Then
            MessageBox.Show("Please select an item from the list.",
                            "Update Data : iBasskung Tutorial", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            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 Data : 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"

            PerformCRUD(SQL, "Update")

            MsgBox("The record has been updated!", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information, "Insert 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.")
            Exit Sub
        End If

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

        Try

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

            PerformCRUD(SQL, "Delete")

            MsgBox("The record has been deleted!!!", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information, "Insert 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

            LoadData()
            ResetMe()

        Catch ex As Exception
            MsgBox("An error occured: " & ex.Message.ToString(), MsgBoxStyle.OkOnly Or MsgBoxStyle.Information, "Search Function : iBasskung Tutorial")
        Finally

            'KeywordTextBox.Clear()
            'KeywordTextBox.Select()
            ' OR
            With KeywordTextBox
                .Text = ""
                .Select()
            End With
        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