how to create database program in visual basic 2019 using access database

Sheelnath Kekre 121 Reputation points
2020-12-30T13:33:55.537+00:00

how to create database program in visual basic 2019 using access database

Developer technologies VB
0 comments No comments
{count} votes

Accepted answer
  1. Karen Payne MVP 35,586 Reputation points Volunteer Moderator
    2020-12-30T16:05:03.683+00:00

    Hello @Sheelnath Kekre

    Although your question is too broad to provide one solution you can take a look at my GitHub repository on Microsoft Access. The repository projects were created in VS2017 and will work with VS2019. There are 42 projects in this repository and yet does not cover all the bases needed but does provide enough code to make an informed decision on how to proceed.

    Here are some questions that would help fine tune what you are looking for

    • Do you have a decent understanding for creating a relational database in MS-Access? It's rare to have one table to store data while multiple related tables are common. To get an idea for designing a database which is database agnostic see the following page.
    • There are a handful of paths to take for interacting with data e.g. DataAdapter, connection/command objects, Entity Framework Core using the following provider or TableAdapter (will at first appear easy but unless you take time to understand them they will bite you at some point). Have you tried any of them out
    • Are you looking for a all encompassing code sample project? If so there are really not any out there, especially for VB.NET, instead take the time to studying code samples such as the one I pointed too.
    • Have (if a needed) considered securing your database?
    • Have you considered not using MS-Access and using SQL-Server Express edition (which is free and a more robust database which offer more than MS-Access)?

      Notes

    • What is considered bad practice is to place data operation code directly in a form.
    • A DataAdapter with one or more INNER JOIN when calling the adapter update method will not work properly without extra code to inform a value from a child table has changed (usually this is a key into a reference table).
    • A Connection should be created, open and closed as needed rather than one private connection object in your data class
    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Peter Fleischer (former MVP) 19,341 Reputation points
    2020-12-30T17:12:52.833+00:00

    Hi,
    try following simple demo:

    Imports System.Data.OleDb
    
    Public Class Form1
    
    #Region " simulate Designer"
      Private WithEvents Button1 As New Button With {.Text = "Load data", .Dock = DockStyle.Top}
      Private WithEvents Button2 As New Button With {.Text = "Save data", .Dock = DockStyle.Top}
      Private DataGridView1 As New DataGridView With {.Dock = DockStyle.Fill}
    
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.Controls.AddRange(New Control() {DataGridView1, Button2, Button1})
      End Sub
    #End Region
    
      ' ConnectionString with path (data source) to access file in directory of exe '
      Private connString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Test.accdb;"
    
      ' Connection to access file, instantiating on first using '
      Private _connection As OleDbConnection
      Private ReadOnly Property Connection As OleDbConnection
        Get
          If Me._connection Is Nothing Then Me._connection = New OleDbConnection(connString)
          Return Me._connection
        End Get
      End Property
    
      ' DataAdatper for loading and updating data in access file '
      Private _dataAdapter As OleDbDataAdapter
      Private ReadOnly Property DataAdapter As OleDbDataAdapter
        Get
          If Me._dataAdapter Is Nothing Then
            Me._dataAdapter = New OleDbDataAdapter("SELECT RecipeID, RecipeName, OtherData FROM Tab1", Me.Connection)
            Dim cb As New OleDbCommandBuilder(Me._dataAdapter)
          End If
          Return Me._dataAdapter
        End Get
      End Property
    
      ' buffer for data '
      Private Data As DataTable
    
      ' Load data from access file '
      Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Data = New DataTable
        DataAdapter.Fill(Data)
        DataGridView1.DataSource = New BindingSource With {.DataSource = Data}
      End Sub
    
      ' Save changed, added and deleted data '
      Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        If Data IsNot Nothing Then DataAdapter.Update(Data)
      End Sub
    
    End Class
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.