【发布时间】:2008-12-16 22:33:41
【问题描述】:
我正在尝试将数据集检索到 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
谢谢
【问题讨论】: