With Coding - Vb.net Project
Using conn As SqlConnection = GetConnection() Using adapter As New SqlDataAdapter(query, conn) adapter.Fill(dataTable) End Using End Using
If rowsAffected > 0 Then MessageBox.Show("Student updated successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information) ClearFields() LoadAllStudents() Else MessageBox.Show("Student not found.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error) End If End Using End Using End If End Sub Vb.net Project With Coding
' Validate input fields Private Function ValidateInputs() As Boolean If String.IsNullOrWhiteSpace(txtName.Text) Then MessageBox.Show("Name is required.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Warning) Return False End If Using conn As SqlConnection = GetConnection() Using adapter
' Search by Name Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click Dim searchValue As String = txtSearch.Text.Trim() 0 Then MessageBox.Show("Student updated successfully!"
conn.Open() Dim rowsAffected As Integer = cmd.ExecuteNonQuery() conn.Close()
Using conn As SqlConnection = GetConnection() Using cmd As New SqlCommand(query, conn) cmd.Parameters.AddWithValue("@StudentID", Convert.ToInt32(txtStudentID.Text)) cmd.Parameters.AddWithValue("@Name", txtName.Text.Trim()) cmd.Parameters.AddWithValue("@Age", numAge.Value) cmd.Parameters.AddWithValue("@Course", txtCourse.Text.Trim())