
<% @Import Namespace="System.Data" %>
<% @Import Namespace="System.Data.SqlClient" %>
<HTML>
	<HEAD>
		<title>使用带输入参数的存储过程示例</title>
		<script language=C# runat=server>
		
			void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
			{
				string ConnStr = System.Configuration.ConfigurationSettings.AppSettings["ConnectionSqlServer"];

				// 创建数据库操作对象
				SqlDataAdapter myAdapter = new SqlDataAdapter();
				SqlCommand myCommand = new SqlCommand();
				myCommand.Connection = new SqlConnection(ConnStr);
				DataTable dt = new DataTable();

				// 指定要调用的存储过程名称 "Customer_Select"
				// 指定SqlCommand对象的命令类型为 "StoredProcedure"枚举值
				myCommand.CommandText = "Customer_Select";
				myCommand.CommandType = CommandType.StoredProcedure;

				// 创建SqlParameter对象，指定参数名称、数据类型、长度及参数值
				SqlParameter para = new SqlParameter("@country", SqlDbType.NVarChar, 15);
				para.Value = DropDownList1.SelectedValue;
				
				myCommand.Parameters.Add(para);

				// 关联SqlDataAdapter与SqlCommand对象
				myAdapter.SelectCommand = myCommand;
				myAdapter.Fill(dt);

				// 绑定DataGrid
				DataGrid1.DataSource = dt;
				DataGrid1.DataBind();
			}
		
		</script>
	</HEAD>
	<body>
		<form id="Form1" method="post" runat="server">
			<h3>使用带输入参数的存储过程示例</h3>
			请选择：
			<asp:DropDownList id="DropDownList1" runat="server" AutoPostBack="True" 
				OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
				<asp:ListItem Value="USA">USA</asp:ListItem>
				<asp:ListItem Value="UK">UK</asp:ListItem>
				<asp:ListItem Value="France">France</asp:ListItem>
				<asp:ListItem Value="Canada">Canada</asp:ListItem>
				<asp:ListItem Value="Norway">Norway</asp:ListItem>
			</asp:DropDownList><BR>
			<BR>
			选择结果：
			<br>
			<asp:DataGrid id="DataGrid1" runat="server"></asp:DataGrid>
		</form>
	</body>
</HTML>
