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?
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.
Comments