Binding to a DataSet - Demo
Notice that the ObjectDataSource control here includes two properties named 'TypeName'
and 'SelectMethod'. The TypeName property contains the name of the component that
you want to represent with the ObjectDataSource control. The SelectMethod represents
the method of the component that you want to call when selecting data.
*** MovieDataSet.vb ***
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.Configuration
Public Class MovieDataSet
Private ReadOnly _conString As String
Public Function GetMovies() As DataSet
' Create DataAdapter
Dim commandText As String = "SELECT Id,Title,Director FROM Movies"
Dim dad As New SqlDataAdapter(commandText, _conString)
' Return DataSet
Dim dstMovies As New DataSet()
Using dad
dad.Fill(dstMovies)
End Using
Return dstMovies
End Function
Public Sub New()
_conString = WebConfigurationManager.ConnectionStrings("MyDatabase").ConnectionString
End Sub
End Class
*** ShowMovieDataSet.aspx ***
<%@ Page Language="VB" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Show Movie DataSet</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView
id="grdMovies"
DataSourceID="srcMovies"
Runat="server" />
<asp:ObjectDataSource
id="srcMovies"
TypeName="MovieDataSet"
SelectMethod="GetMovies"
Runat="server" />
</div>
</form>
</body>
</html>