0
我試圖將數據集檢索到Gridview,但我只是沒有在Gridview中獲取任何行。我究竟做錯了什麼?無法獲取數據Gridview
頁面代碼
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
用來獲取數據的類功能
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
感謝