
<% @Import Namespace="System.Data" %>
<% @Import Namespace="System.Data.SqlClient" %>
<HTML>
	<HEAD>
		<title>使用DataTable存储数据库表内容的示例</title>
		<script language=C# runat=server>

			void Page_Load(object sender, System.EventArgs e)
			{
				// 连接字符串及SQL语句
				string ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionSqlServer"];
				string Sql = "SELECT EmployeeID, LastName, FirstName, BirthDate FROM Employees";

				// 创建SqlConnection、SqlDataAdapter对象
				SqlConnection thisConnection = new SqlConnection(ConnectionString);
				SqlDataAdapter adapter = new SqlDataAdapter(Sql, thisConnection);

				// 创建DataTable对象
				DataTable table = new DataTable();

				// 填充数据到DataTable
				adapter.Fill(table);

				// 将DataTable绑定到DataGrid控件
				myDataGrid.DataSource = table;
				myDataGrid.DataBind();
			}

		</script>
	</HEAD>
	<body>
		<form id="Form1" method="post" runat="server">
		<h3>使用DataTable存储数据库表内容的示例</h3>
			<asp:DataGrid id="myDataGrid" runat="server"></asp:DataGrid>
		</form>
	</body>
</HTML>
