First Import the following dll's
Imports System.Data
Imports System.Data.OleDb
To create connection between application and Database
Public Sub OpenConnection()
If con.State = ConnectionState.Open Then
con.Close()
End If
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\DatabaseName.mdb"
Try
con.Open()
Catch ex As Exception objda.SelectCommand = New OleDbCommand
objda.UpdateCommand = New OleDbCommand
objda.SelectCommand.Connection = con objda.UpdateCommand.Connection = con
End Sub
Adding New Data is nothing but the clearing the Textbox fields
Texbox1.Clear
Texbox2.Clear
To Save data form Texbox fields to Access Daabase
objda.SelectCommand.CommandText = "Insert into TableName(Field1, Field2) values(@Field1, @Field2)"
objda.SelectCommand.Parameters.AddWithValue("@StudID", txtstudid.Text)
Try
OpenConnection()
objda.SelectCommand.ExecuteNonQuery()
MessageBox.Show("Information saved Successfully", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As OleDb.OleDbException
MessageBox.Show(ex.Message)
End Try
To Upadate Values present into the Database
objda.UpdateCommand.CommandText = "Update TableName SET Field1='" & txtstudname.Text & "', Field2='" & txtmother.Text & "'"
Try
OpenConnection()
objda.UpdateCommand.ExecuteNonQuery()
MessageBox.Show("Information Modified Successfully", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As OleDb.OleDbException
MessageBox.Show(ex.Message)
End Try
To Delete the record from Detabase
objda.SelectCommand.CommandText = "DELETE * FROM TableName WHERE Field1='" & Textbox1.Text & "'"
Try
OpenConnection()
objda.SelectCommand.ExecuteNonQuery()
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try