I’m trying to retrive a dataset to a Gridview, but I just don’t get any row in my Gridview. What am I doing wrong?
the page code
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load CType(Master, AreaTrabalho).AlteraTitulo = 'Projectos' Using oSQL As New clsSQL(System.Configuration.ConfigurationManager.AppSettings('ConnectionString1')) If oSQL.OpenConnection Then oSQL.ToDataGrid(Me.GridView1, 'Select * from users') End If End Using End Sub
the class functions used to fetch data
Public Function ToDataGrid(ByVal oDataGrid As GridView, _ ByVal sQuery As String, _ Optional ByVal sTable As String = '') As Boolean Try Dim objDataSet As New Data.DataSet 'Preenche o dataset objDataSet = ToDataSet(sQuery, sTable) oDataGrid.DataSource = objDataSet.Tables(0) objDataSet.Dispose() objDataSet = Nothing Return True Catch ex As Exception RaiseEvent OnError('ToDataGrid', ex) End Try End Function Public Function ToDataSet(ByVal sQuery As String, Optional ByVal sTable As String = '') As Data.DataSet Try m_objCommand = New SqlCommand(sQuery, m_objConnection) Dim objDataSet As New Data.DataSet Dim objSqlDataAdapter As SqlDataAdapter = New SqlDataAdapter(m_objCommand) 'Verifica se foi defenido a tabela If sTable = '' Then objSqlDataAdapter.Fill(objDataSet) Else objSqlDataAdapter.Fill(objDataSet, sTable) End If objSqlDataAdapter.Dispose() objSqlDataAdapter = Nothing Return objDataSet Catch ex As Exception RaiseEvent OnError('ToDataSet', ex) Return Nothing End Try End Function
Thanks
You are not calling the Databind method on the GridView after setting the datasource in your ToDataGrid method: