Click here to Skip to main content
15,665,229 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello there,

I've always used datagridview with local ms access db, without any troubles.
I've been asked to create a solution, so that users can select, add, delete data from one table. The problem is that the path to this db is not the same for everyone.

I'm using this:

Imports System.Data.OleDb
Module Module1
    Dim con As New OleDbConnection
    Public Sub Get_Connection()
        con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source = " & My.Settings.BDpath
    End Sub

    Public Sub DisplayDataGrid()
        Dim lista As New Form3


        Dim ds As New DataSet
        Dim dt As New DataTable
        Dim da As New OleDbDataAdapter
        Dim cmd As String

        cmd = "Select * From Registo;"

        da = New OleDbDataAdapter(cmd, con)
        lista.DataGridView1.DataSource = dt.DefaultView
    End Sub

my.settings.bdpath text is = "C:\Users\fcosta\Desktop"

i've set it to run when form is loaded, but i can't get it to work.

Public Class Form3

    Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    End Sub

End Class

What I have tried:

I've pretty much read the first two pages of google relationed with datagridviews and still, can't get it to work.
Updated 28-Mar-16 8:08am
CHill60 28-Mar-16 13:47pm    
Well you could be consistent and put the database into C:\ProgramData\afolder.
Whichever method you use where are you calling the function Get_Connection (it is not in the code you have shared). I presume you are getting an error when you try to run this - what is that error?
Fjcosta 28-Mar-16 14:13pm    
@CHill60 - My bad, i've already updated the question. Get_Connection is being called the same way as Displaydatagrid().
I'd put the db in a path, but it's stored over a network. When mapping the network, users get varius letters assign:


i'm not getting any error, the form is loaded with displaying any data. i've checked the connection, and it's working.
CHill60 28-Mar-16 15:35pm    
When you step through the code in the debugger is dt being populated?
AJ_Smit 29-Mar-16 4:14am    
Instead of ...

lista.DataGridView1.DataSource = dt.DefaultView

Try adding the data with NewRow() method in a for loop, let me know whether that works, I have noticed that in some cases DataAdapter does fail when trying to retrieve data from the DB

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900