Bind ListView to DataTable
T-SQL:
CREATE PROCEDURE GetMembers
AS
SET NOCOUNT ON
SELECT
FirstName,
LastName,
NickName,
FavoriteLanguage
FROM
Members
VB.NET
Private Function GetMembers() As DataTable
Dim connection As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
Dim command As SqlCommand = connection.CreateCommand
command.CommandText = "GetMembers"
command.CommandType = Data.CommandType.StoredProcedure
Dim table As New DataTable
connection.Open()
table.Load(command.ExecuteReader(Data.CommandBehavior.CloseConnection))
Return table
End Function
Protected Sub Page_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Me.Load
Me.ListView1.DataSource = GetMembers()
Me.ListView1.DataBind()
End Sub
沒有留言:
張貼留言