Code For CRUD Form
Code For CRUD Form
Imports System.Data.OleDb
Public Class CRUD
Dim con As OleDbConnection
Dim adapter As OleDbDataAdapter
Dim dataset As DataSet
Dim bindingSource As BindingSource
Dim cmd As OleDbCommand
Dim currentPosition As Integer = 0
' Open the connection, execute the command, and close the connection
con.Open()
Dim rowsAffected As Integer = cmd.ExecuteNonQuery()
con.Close()
End Sub
Try
' Create the SQL command to update data in the database
cmd = New OleDbCommand("UPDATE FORM3 SET FName = @FName, Surname =
@Surname, Class = @Class, Age = @Age, EnrollDate = @EnrollDate WHERE StudentID =
@StudentID", con)
' Open the connection, execute the command, and close the connection
con.Open()
Dim rowsAffected As Integer = cmd.ExecuteNonQuery()
con.Close()
Catch ex As Exception
MessageBox.Show("An error occurred: " & ex.Message)
Finally
' Ensure the connection is closed in case of an error
If con.State = ConnectionState.Open Then
con.Close()
End If
End Try
End Sub
' Open the connection, execute the command, and close the connection
con.Open()
Dim rowsAffected As Integer = cmd.ExecuteNonQuery()
con.Close()
End Sub
Try
' Initialize the adapter with the search query
adapter = New OleDbDataAdapter(query, con)