17-11-24, 11:37 PM
Private Sub btnAddStudent_Click(sender As Object, e As EventArgs) Handles btnAddStudent.Click
Try
Dim studentId As String = txtStudentId.Text
Dim studentName As String = txtStudentName.Text
Dim birthDate As Date = dtpBirthDate.Value
Dim query As String = "INSERT INTO Students (StudentID, StudentName, BirthDate) VALUES (@StudentID, @StudentName, @BirthDate)"
Dim command As New OleDbCommand(query, connection)
command.Parameters.AddWithValue("@StudentID", studentId)
command.Parameters.AddWithValue("@StudentName", studentName)
command.Parameters.AddWithValue("@BirthDate", birthDate)
command.ExecuteNonQuery()
MessageBox.Show("Student added successfully.")
LoadStudentData()
Catch ex As Exception
MessageBox.Show("Error adding student: " & ex.Message)
End Try
End Sub
Try
Dim studentId As String = txtStudentId.Text
Dim studentName As String = txtStudentName.Text
Dim birthDate As Date = dtpBirthDate.Value
Dim query As String = "INSERT INTO Students (StudentID, StudentName, BirthDate) VALUES (@StudentID, @StudentName, @BirthDate)"
Dim command As New OleDbCommand(query, connection)
command.Parameters.AddWithValue("@StudentID", studentId)
command.Parameters.AddWithValue("@StudentName", studentName)
command.Parameters.AddWithValue("@BirthDate", birthDate)
command.ExecuteNonQuery()
MessageBox.Show("Student added successfully.")
LoadStudentData()
Catch ex As Exception
MessageBox.Show("Error adding student: " & ex.Message)
End Try
End Sub
