Can't get Gridview data

I'm trying to restore a dataset in a Gridview, but I just don't get a row in my Gridview. What am I doing wrong?

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

      

class functions used to retrieve 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

      

thank

0


source to share


2 answers


You don't call the Databind method on the GridView after setting the datasource in the ToDataGrid method:



oDataGrid.DataBind()

      

+2


source


I am assuming this is a webforms application which, if so, you need to call GridView.DataBind()

after you have set up the datasource to bind the data to the grid.



+2


source







All Articles