
<% @Import Namespace="System.Data" %>
<% @Import Namespace="System.Data.SqlClient" %>
<HTML>
	<HEAD>
		<title>在 ASP.NET 使用存储过程示例</title>

		<script language=C# runat=server>

		void Page_Load(object sender, System.EventArgs e)
		{
			// 连接字符串
			string ConnStr = System.Configuration.ConfigurationSettings.AppSettings["ConnectionSqlServer"];

			// 创建Connection对象
			SqlConnection myConn = new SqlConnection(ConnStr);

			// 创建Command对象并和Connection对象关联
			SqlCommand myCommand = new SqlCommand();
			myCommand.Connection = myConn;
			
			// 指定要执行的存储过程名称
			myCommand.CommandText = "CustomersProc";
			// 使用要执行的是存储过程
			myCommand.CommandType = CommandType.StoredProcedure;

			// 创建DataAdapter对象填充数据
			DataSet myDS = new DataSet();
			SqlDataAdapter adapter = new SqlDataAdapter(myCommand);
			adapter.Fill(myDS, "Customers");

			// 将返回的数据和DataGrid绑定显示
			myDataGrid.DataSource = myDS.Tables["Customers"];
			myDataGrid.DataBind();
		}
		
		</script>

	</HEAD>
	<body>
		<form id="Form1" method="post" runat="server">
			<h3>在 ASP.NET 使用存储过程示例</h3>
			<asp:DataGrid id="myDataGrid" runat="server"></asp:DataGrid>
		</form>
	</body>
</HTML>
