📄 procedureexample3.aspx
字号:
<% @Import Namespace="System.Data" %>
<% @Import Namespace="System.Data.SqlClient" %>
<HTML>
<HEAD>
<title>使用带输入、输出参数的存储过程示例</title>
<script language=C# runat=server>
void myDropDownList_SelectedIndexChanged(object sender, System.EventArgs e)
{
string ConnStr = System.Configuration.ConfigurationSettings.AppSettings["ConnectionSqlServer"];
// 创建 Connection 和 Command 对象
SqlConnection myConn = new SqlConnection(ConnStr);
SqlCommand myCommand = new SqlCommand("EmployeesProc", myConn);
// 指定要执行的命令为存储过程
myCommand.CommandType = CommandType.StoredProcedure;
// 增加输入参数并赋值
myCommand.Parameters.Add("@TitleOfCourtesy", SqlDbType.NVarChar, 20);
myCommand.Parameters["@TitleOfCourtesy"].Value = myDropDownList.SelectedItem.Text;
myCommand.Parameters["@TitleOfCourtesy"].Direction = ParameterDirection.Input;
// 增加输出参数
myCommand.Parameters.Add("@empCount", SqlDbType.Int);
myCommand.Parameters["@empCount"].Direction = ParameterDirection.Output;
// 创建 DataAdapter 对象填充数据
DataSet myDS = new DataSet();
SqlDataAdapter adapter = new SqlDataAdapter(myCommand);
adapter.Fill(myDS, "Customers");
// 使用 Label 控件显示输出参数的输出值
rtnLabel.Text = myCommand.Parameters["@empCount"].Value.ToString();
// 将返回的数据和 DataGrid 绑定显示
myDataGrid.DataSource = myDS.Tables["Customers"];
myDataGrid.DataBind();
}
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<h3>使用带输入、输出参数的存储过程示例</h3>
请选择:
<asp:DropDownList id="myDropDownList"
runat="server" AutoPostBack="True"
OnSelectedIndexChanged="myDropDownList_SelectedIndexChanged">
<asp:ListItem Value="Ms.">Ms.</asp:ListItem>
<asp:ListItem Value="Dr.">Dr.</asp:ListItem>
<asp:ListItem Value="Mrs.">Mrs.</asp:ListItem>
<asp:ListItem Value="Mr.">Mr.</asp:ListItem>
</asp:DropDownList>
<BR>
<BR>
记录数:
<asp:Label id="rtnLabel" runat="server"></asp:Label>条<BR>
<asp:DataGrid id="myDataGrid" runat="server"></asp:DataGrid>
</form>
</body>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -