Using conn As SqlConnection = GetConnection() Using adapter As New SqlDataAdapter(query, conn) adapter.Fill(dataTable) End Using End Using
CREATE DATABASE StudentDB; GO USE StudentDB; GO
| Control Type | Name | Text / Purpose | |--------------|------|----------------| | Label | - | "Student Management System" (Font: bold) | | Label | - | "Student ID" | | TextBox | txtStudentID | (ReadOnly for auto-generated ID) | | Label | - | "Name" | | TextBox | txtName | | | Label | - | "Age" | | NumericUpDown | numAge | Minimum=1, Maximum=100 | | Label | - | "Course" | | TextBox | txtCourse | | | Button | btnAdd | Add Student | | Button | btnUpdate | Update | | Button | btnDelete | Delete | | Button | btnClear | Clear Fields | | TextBox | txtSearch | Search box | | Button | btnSearch | Search | | DataGridView | dgvStudents | (Dock: Bottom, Anchor: Top,Bottom,Left,Right) | Create a new module DatabaseHelper.vb :
If dataTable.Rows.Count = 0 Then MessageBox.Show("No students found.", "Search Result", MessageBoxButtons.OK, MessageBoxIcon.Information) End If End Sub
If String.IsNullOrEmpty(searchValue) Then LoadAllStudents() Return End If
' 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
If String.IsNullOrWhiteSpace(txtCourse.Text) Then MessageBox.Show("Course is required.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Warning) Return False End If
' 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)"
Dim query As String = "SELECT StudentID, Name, Age, Course FROM Students WHERE Name LIKE @Search + '%'" Dim dataTable As New DataTable()
conn.Open() cmd.ExecuteNonQuery() conn.Close() End Using End Using