Click here to Skip to main content
15,885,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm trying to fill a datagridview with data.

the commented lines are the things i've tried but i don't get results...
can you help me (i'm a beginner : first timer doing this type of coding)

What I have tried:

my current code is this: 
<pre>Imports System.Data
Imports System.Data.OleDb
Public Class Dossiers
    Private DossierDataset As DataSet = New DataSet()
    Private Sub Dossiers_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim connString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=F:\GoogleDrive\EINDWERK VBNET\PatientenDatabase.accdb"
        Using con As OleDbConnection = New OleDbConnection(connString)
            con.Open()
            Dim cmd As OleDbCommand = New OleDbCommand
            cmd.Connection = con
            cmd.CommandText = "SELECT          tbl_Dossiers.Dos_ID, tbl_Relaties.Rel_Naam, tbl_Relaties.Rel_Voornaam, tbl_Onderzoekstypes.OZ_TypeOnderzoek, tbl_Diagnoses.Diag_Type
                               FROM            ((((tbl_Dossiers 
                               LEFT OUTER JOIN tbl_DossRelatie ON tbl_Dossiers.Dos_ID = tbl_DossRelatie.DR_DossID) 
                               LEFT OUTER JOIN tbl_Relaties ON tbl_DossRelatie.DR_RelID = tbl_Relaties.Rel_ID) 
                               LEFT OUTER JOIN tbl_OnderzoeksTypes ON tbl_Dossiers.OZ_ID = tbl_OnderzoeksTypes.OZ_ID) 
                               LEFT OUTER JOIN tbl_Diagnoses ON tbl_Dossiers.Diag_ID = tbl_Diagnoses.Diag_ID)
                               ORDER BY        tbl_Dossiers.Dos_ID"
            Dim adpt As OleDbDataAdapter = New OleDbDataAdapter(cmd)
            adpt.Fill(DossierDataset)
            dgvDossiers.DataSource = DossierDataset.Tables

        End Using
        'dgvDossiers.DataSource = Me.DossierDataset
        'dgvDossiers.AutoGenerateColumns = True
        'dgvDossiers.DataSource = DossierDataset
        'dgvDossiers.DataMember = "tbl_Dossier"
    End Sub
    'Private Sub BindData()
    'With dgvDossiers
    '.AutoGenerateColumns = True
    '.DataSource = DossierDataset
    '.DataMember = "Dos_ID"
    'End With
    'End Sub
Posted
Updated 4-Nov-20 5:28am

Try this:
dgvDossiers.DataSource = DossierDataset.Tables(0)
 
Share this answer
 
Comments
Izzy Decorte 4-Nov-20 6:08am    
Hi RickZeeland. I added the (0) as described but I still won't get any data in the list. Thanks for helping out!
RickZeeland 4-Nov-20 6:48am    
Bummer, maybe you can try setting a breakpoint and hover over DossierDataset with the mouse to see if it contains anything, good luck!
Izzy Decorte 4-Nov-20 7:22am    
It just says dgvDossiers [System.windows.forms.datagridview]
if i open the arrow for more info, i get the datagridview info like "allowusertoaddrows" = true etc etc
RickZeeland 4-Nov-20 8:04am    
And can you see anything in DossierDataset ?
If not your connectionstring could be wrong for instance.
Izzy Decorte 4-Nov-20 10:01am    
If i check the query i get actual feedback in de query designer, the connectionstring is the same one i use everywhere (copy pasted)
found it!
basically i made too much effort in the datagridview itself in the form.
Because i made it look like the way i wanted it to, i changed data that was critical to the loading
correct code:

Private Sub Dossiers_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim str As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=F:\GoogleDrive\EINDWERK VBNET\PatientenDatabase.accdb"
        Dim con As New OleDbConnection(str)
        Dim com As String = "Select          tbl_Dossiers.Dos_ID, tbl_Relaties.Rel_Naam, tbl_Relaties.Rel_Voornaam, tbl_Onderzoekstypes.OZ_TypeOnderzoek, tbl_Diagnoses.Diag_Type
                               FROM((((tbl_Dossiers 
                               Left OUTER JOIN tbl_DossRelatie ON tbl_Dossiers.Dos_ID = tbl_DossRelatie.DR_DossID) 
                               Left OUTER JOIN tbl_Relaties ON tbl_DossRelatie.DR_RelID = tbl_Relaties.Rel_ID) 
                               Left OUTER JOIN tbl_OnderzoeksTypes ON tbl_Dossiers.OZ_ID = tbl_OnderzoeksTypes.OZ_ID) 
                               Left OUTER JOIN tbl_Diagnoses ON tbl_Dossiers.Diag_ID = tbl_Diagnoses.Diag_ID)
                               ORDER BY        tbl_Dossiers.Dos_ID"
        Dim adpt As New OleDbDataAdapter(com, con)
        Dim dossierset As New DataSet()
        adpt.Fill(dossierset, "Dos_ID")
        dgvDossiers.DataSource = dossierset.Tables(0)
        dgvDossiers.Show()

    End Sub


thanks for helping out!
 
Share this answer
 
Comments
RickZeeland 4-Nov-20 12:27pm    
Knew you could do it! I never use DataAdapters so could not be of much help regarding that sadly.
Izzy Decorte 4-Nov-20 14:20pm    
@RickZeeland: Thanks for checking up anyhow ,the (0) helped out although i'm still not sure why (very bad at this)...
I'm working on my next problem now, "add new dossier button" opens new form where i can make a new dossier... probably gonna need help for that too, you'll see that when it happens haha.

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