I'm trying to open the database by access and then I run the application in vb.net then an error appears
File already in use.
If I don't open the MS-ACCESS database then running the application has no problems. Is there a solution with code or or is there something wrong with my code? . Please guide.
Thanks
Imports System.Data.OleDb
Public Class Form1
Dim Path As String = "|DataDirectory|\students.accdb"
Private WithEvents dt As New DataTable
Dim cn = "Provider=Microsoft.ACE.OLEDB.12.0; data source=" & Path & "; Persist Security Info=False;"
Private Sub PopulateDataGridView()
Try
dt = New DataTable
Dim query = "select * FROM [students]"
Using adapter As New OleDbDataAdapter(query, cn.ToString)
adapter.Fill(dt)
End Using
Me.DataGridView1.DataSource = dt
Catch myerror As OleDbException
MessageBox.Show("Error: " & myerror.Message)
Finally
'cn.Dispose()
End Try
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.PopulateDataGridView()
End Sub
End Class

