title: Updating an Access Database via a DataGridView Using OLEDB in VB.NET
body: <p>I have linked an Access database to my program. It populates the DataGridView as it is intended to so that part of the program works. However, I'm trying to get the DataGridView to update the Access database file with any changes that are made to it but after countless attempts at trying to fix my code or looking for an alternative solution, I am stumped.</p>
  
  <p>Can anyone see anything wrong or something I've missed out that would cause the code not to function as desired? Thank you in advance.</p>
  
  <pre><code>Imports System.Data.OleDb
  
  Public Class frmDatabase
  
  Dim con As New OleDbConnection
  Dim ds As New DataSet
  Dim dt As New DataTable
  Dim da As New OleDbDataAdapter
  
  
  Private Sub frmDatabase_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  
      con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Joe\Documents\Visual Studio 2012\Projects\school database viewer\school database viewer\dbSchoolDatabase.mdb"
      con.Open()
      ds.Tables.Add(dt)
      da = New OleDbDataAdapter("Select * from tableStudentDetails", con)
      da.Fill(dt)
      dgvStudentDetails.DataSource = dt.DefaultView
      con.Close()
  
  End Sub
  
  Private Sub cmdUpdate_Click(sender As Object, e As EventArgs) Handles cmdUpdate.Click
  
      con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Joe\Documents\Visual Studio 2012\Projects\school database viewer\school database viewer\dbSchoolDatabase.mdb"
      con.Open()
      ds.Tables.Add(dt)
      da = New OleDbDataAdapter("Select * from tableStudentDetails", con)
      da.Update(dt)
      con.Close()
  
  End Sub
  End Class
  </code></pre>