Vb.net Access Database Example Apr 2026
Introduction Connecting a VB.NET application to a Microsoft Access database is one of the most common tasks for desktop developers. Whether you're building a small inventory system, a contact manager, or a data entry application, this guide will walk you through everything you need to know.
Using conn As New OleDbConnection(connectionString) Using adapter As New OleDbDataAdapter(query, conn) Dim table As New DataTable() adapter.Fill(table) dgvUsers.DataSource = table End Using End Using vb.net access database example
' Get the UserID from the selected row Dim userID As Integer = Convert.ToInt32(dgvUsers.SelectedRows(0).Cells("UserID").Value) Introduction Connecting a VB
Private Sub LoadData() Dim query As String = "SELECT * FROM Users" Using conn As New OleDbConnection(connectionString) Using adapter As New OleDbDataAdapter(query, conn) Dim table As New DataTable() adapter.Fill(table) dgvUsers.DataSource = table End Using End Using End Sub a contact manager
Using conn As New OleDbConnection(connectionString) Using cmd As New OleDbCommand(query, conn) cmd.Parameters.AddWithValue("@FirstName", txtFirstName.Text) cmd.Parameters.AddWithValue("@LastName", txtLastName.Text) cmd.Parameters.AddWithValue("@Email", txtEmail.Text) cmd.Parameters.AddWithValue("@Age", Convert.ToInt32(txtAge.Text)) cmd.Parameters.AddWithValue("@UserID", userID) conn.Open() cmd.ExecuteNonQuery() conn.Close() End Using End Using
MessageBox.Show("Record updated successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information) LoadData() End Sub Add this to the Delete button:
[First Name: TextBox1] [Last Name: TextBox2] [Email: TextBox3] [Age: TextBox4] [Load] [Insert] [Update] [Delete]