<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<html>
<title>Retrieving SQL Data Into a DataSet</title>
<link rel="stylesheet" href="/shared/netdemos.css">
<script language="C#" runat="server" src="fetchData_sql.cs" />
<script language="C#" runat="server" src="displayData.cs" />
<script runat="server">
protected void Page_Load ( object src, EventArgs e ) {
// set up the connection
SqlConnection myConn = new SqlConnection ( getConnection ( "aspnet" ) );
// set up the query
string query = "SELECT CustomerID, CompanyName, ContactName, Address, City, Country FROM Customers";
// initialize dataadapter
SqlDataAdapter myCmd = new SqlDataAdapter ( query, myConn );
// initialize dataset object
DataSet myData = new DataSet ( );
// fill dataset with query results
myCmd.Fill ( myData, "Customers" );
// call method to display dataset contents into html table
displayData ( myData );
}
</script>
<body>
<!-- #include virtual="~/shared/top.inc -->
<div class="header"><h2>ADO.NET Primer: Retrieving <b>SQL</b> Data Into a DataSet</h2></div>
<!-- #include virtual="~/shared/viewsrc_top.inc" -->
<hr size=1 width=92%>
<form runat="server">
<p align="center">
<%= html %>
</p>
</form>
<hr size=1 width=92%>
<!-- #include virtual="~/shared/viewsrc.inc" -->
</body>
</html>