Vb.net Project With Coding -

conn.Open() cmd.ExecuteNonQuery() conn.Close() End Using End Using

Using conn As SqlConnection = GetConnection() Using cmd As New SqlCommand(query, conn) cmd.Parameters.AddWithValue("@Search", searchValue) Using adapter As New SqlDataAdapter(cmd) adapter.Fill(dataTable) End Using End Using End Using

' Add Student Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click If ValidateInputs() Then Dim query As String = "INSERT INTO Students (Name, Age, Course) VALUES (@Name, @Age, @Course)"

' Delete Student Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click If String.IsNullOrWhiteSpace(txtStudentID.Text) Then MessageBox.Show("Please select a student to delete.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning) Return End If Vb.net Project With Coding

' Load all students into DataGridView Private Sub LoadAllStudents() Dim query As String = "SELECT StudentID, Name, Age, Course FROM Students" Dim dataTable As New DataTable()

conn.Open() Dim rowsAffected As Integer = cmd.ExecuteNonQuery() conn.Close()

Using conn As SqlConnection = GetConnection() Using adapter As New SqlDataAdapter(query, conn) adapter.Fill(dataTable) End Using End Using Course) VALUES (@Name

Using conn As SqlConnection = GetConnection() Using cmd As New SqlCommand(query, conn) cmd.Parameters.AddWithValue("@StudentID", Convert.ToInt32(txtStudentID.Text))

dgvStudents.DataSource = dataTable

' Clear all input fields Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click ClearFields() End Sub Name NVARCHAR(100) NOT NULL

Public Function GetConnection() As SqlConnection Return New SqlConnection(connectionString) End Function End Module Imports System.Data.SqlClient Public Class Form1 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load LoadAllStudents() End Sub

CREATE TABLE Students ( StudentID INT PRIMARY KEY IDENTITY(1,1), Name NVARCHAR(100) NOT NULL, Age INT NOT NULL, Course NVARCHAR(100) NOT NULL ); GO