DatagridView not loading from DataTable

user2934164

I'm trying to load data from a database and then presenting it in a DatagridView. I've tried different combinations using different classes like an SQLDataAdapter, DataBinding as per suggestions of various online websites.

However nothing works..

This is my code:

    Dim sql As String

    sql = "select "
    sql = sql & " dbo.tblMvMovimentos.Sigla, dbo.tblMvMovimentos.numero,dbo.tblMvMovimentos.chkdigit,"
    sql = sql & " CodTipocontentor,Dim, dbo.tblMvMovimentos.CodArmador,CodDebito,"
    sql = sql & " DataEntrada, EstadoCarga, PesoBascula, "
    sql = sql & "  FrigoTemperatura, FrigoLigado, Observacoes"

    sql = sql & " from  tblMvMovimentos INNER JOIN dbo.tblCtContentores ON"
    sql = sql & " dbo.tblMvMovimentos.Sigla = dbo.tblCtContentores.Sigla AND"
    sql = sql & " dbo.tblMvMovimentos.Numero = dbo.tblCtContentores.Numero"

    Dim rs As ADODB.Recordset

    Consulta(sql, rs)


    da = New OleDb.OleDbDataAdapter
    ds = New DataTable()
    da.Fill(ds, rs)
    MessageBox.Show(rs.RecordCount)
    MessageBox.Show(ds.Rows.Count)



    With DataGridView1
        .AutoGenerateColumns = False
        .DataSource = ds
        .Refresh()
    End With



    MessageBox.Show(DataGridView1.RowCount)

Consulta is a function which deals with queries to the db. I've written those message boxes to see if data was actually being loaded and it is both to the recordset and to the DataTable. However the last one, refering to the datagrid returns 0 and the datagridview appears all gray. Can anyone point me in the right direction?

Elroy Skimms
With DataGridView1
    .AutoGenerateColumns = True
    .DataSource = ds
    .Refresh()
End With

When you set AutoGenerateColumns = False, you have to define the columns yourself. If you set that to True, it will determine the columns based on the Datasource.

-E

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

DatagridView not loading from DataTable

From Dev

Progressbar for loading data to DataGridView using DataTable

From Dev

DataGridView loses one row from Datatable in TabControl

From Dev

Get DataTable from DataGridView respecting filters and sorting

From Dev

how to pull data from DB/datagridview/datatable

From Dev

Duplicate Rows Loading Data From MySQL to DataGridView

From Dev

Loading img from url to DataGridView in WinForms

From Dev

Host custom controls on DataGridView which populate data from DataTable

From Dev

how to add headers from datatable to datagridview in c#

From Dev

Host custom controls on DataGridView which populate data from DataTable

From Dev

How can you add combobox to datagridview from datatable?

From Dev

Loading cell values in dataGridView from text file C#

From Dev

Only one record is Shown in Datagridview Loading from excel

From Dev

DataGridView binded to DataTable with ComboBox

From Dev

DataGridView selected rows to DataTable

From Dev

DataGridView DataError on Bound DataTable

From Dev

DataGridView binded to DataTable with ComboBox

From Dev

save edited DataGridView to Datatable

From Dev

How to stop loading the data from the previous page in dataTable?

From Dev

Shiny: ProgressBar for loading the data from database to datatable (DT)

From Dev

Loading DataTable from DataSet with correct column widths and format

From Dev

vb.net Loading Images from Access Database to DataTable?

From Dev

Lazy loading in datatable JSF

From Dev

DataTable not loading SqlDataReader

From Dev

Loading DataTable Into ReportViewer

From Dev

Datagridview linked to datatable not getting updated

From Dev

C# DataGridView is not updating with DataTable

From Dev

DataTable/DataGridView Row Number Display

From Dev

DataTable to Pre Defined DataGridView Columns

Related Related

  1. 1

    DatagridView not loading from DataTable

  2. 2

    Progressbar for loading data to DataGridView using DataTable

  3. 3

    DataGridView loses one row from Datatable in TabControl

  4. 4

    Get DataTable from DataGridView respecting filters and sorting

  5. 5

    how to pull data from DB/datagridview/datatable

  6. 6

    Duplicate Rows Loading Data From MySQL to DataGridView

  7. 7

    Loading img from url to DataGridView in WinForms

  8. 8

    Host custom controls on DataGridView which populate data from DataTable

  9. 9

    how to add headers from datatable to datagridview in c#

  10. 10

    Host custom controls on DataGridView which populate data from DataTable

  11. 11

    How can you add combobox to datagridview from datatable?

  12. 12

    Loading cell values in dataGridView from text file C#

  13. 13

    Only one record is Shown in Datagridview Loading from excel

  14. 14

    DataGridView binded to DataTable with ComboBox

  15. 15

    DataGridView selected rows to DataTable

  16. 16

    DataGridView DataError on Bound DataTable

  17. 17

    DataGridView binded to DataTable with ComboBox

  18. 18

    save edited DataGridView to Datatable

  19. 19

    How to stop loading the data from the previous page in dataTable?

  20. 20

    Shiny: ProgressBar for loading the data from database to datatable (DT)

  21. 21

    Loading DataTable from DataSet with correct column widths and format

  22. 22

    vb.net Loading Images from Access Database to DataTable?

  23. 23

    Lazy loading in datatable JSF

  24. 24

    DataTable not loading SqlDataReader

  25. 25

    Loading DataTable Into ReportViewer

  26. 26

    Datagridview linked to datatable not getting updated

  27. 27

    C# DataGridView is not updating with DataTable

  28. 28

    DataTable/DataGridView Row Number Display

  29. 29

    DataTable to Pre Defined DataGridView Columns

HotTag

Archive