VB.NET insert update delete view and search data with SQL database (WITH CODE)

Share

Summary

This video tutorial demonstrates how to perform database operations (insert, update, delete, view, and search) using VB.NET with an SQL database. It covers setting up the project, designing the form, creating an SQL database, and writing the necessary VB.NET code for each operation.

Highlights

Project Setup and Form Design
00:00:00

The video starts by guiding users through creating a new VB.NET Windows Forms Application project. It then demonstrates how to design the user interface by adding text boxes for name and city, and buttons for insert, delete, update, display, and search operations, along with a DataGridView to display data.

Database Creation and Table Setup
00:03:46

Next, the tutorial shows how to add a new SQL Server Database (.mdf file) to the project. Inside the database, a new table named 'Table1' is created with columns for ID (auto-incrementing), Name (varchar(50)), and City (varchar(50)).

Database Connection and Form Load
00:06:23

The video explains how to import the 'System.Data.SqlClient' library and declare SQL connection and command objects. It then details how to establish a database connection within the form's load event, including setting the connection string and opening the connection.

Insert Operation
00:08:30

This section covers writing the code for the insert button. It demonstrates how to create a SQL command, define the insert query with parameters from the text boxes, execute the query, and display a confirmation message. It also shows how to verify the inserted data in the database.

Display Data (View Operation)
00:10:50

The tutorial introduces a public function 'display_data' to fetch all records from 'Table1' and populate the DataGridView. This function is called after an insert operation and when the form loads to show the current data.

Cell Click Event and Row Selection for Update/Delete
00:13:03

To prepare for update and delete operations, the video explains how to handle the DataGridView's 'CellClick' event. It shows how to retrieve the 'ID' of the selected row and populate the text boxes with the corresponding name and city, allowing users to modify or delete specific records. The 'FullRowSelect' property for the DataGridView is also set.

Update Operation
00:18:58

This part details the code for the update button. It demonstrates how to construct an update SQL query, setting the name and city based on the text box values and using the selected ID for the 'WHERE' clause. After execution, the 'display_data' function is called to refresh the DataGridView.

Delete Operation
00:20:30

The video then covers the delete operation. It shows how to write a delete SQL query based on the name from the text box (or ID) and execute it. After successful deletion, the 'display_data' function is used to update the displayed records.

Display All and Search Operations
00:21:32

For the 'Display' button, the existing 'display_data' function is simply called. For the 'Search' button, a modified query is used to select records where the name matches the input in the text box. Finally, a small improvement is shown to clear text boxes after an insert operation.

Recently Summarized Articles

Loading...