使用存储过程从web页面传递参数
来源:互联网 发布:sap系统 知乎 编辑:程序博客网 时间:2024/05/16 10:01
CREAT PROCEDURE sp_CustomersByState @region nvarchar(15)
AS
select CustomerID,CompanyName from Customers
where region=@region Order by CompanyName
RETURN
编写程序代码:
在C#代码中,我们将使用新的类,System.Data.SqlClient.Parameter。该类的对象设计用于表示存储过程中的参数,因此构造函数需要知道名称、数据类型和所讨论的参数的大小。
<%@ Import namespace="System.Data" %>
<%@ Import namespace="System.Data.SqlClient" %>
<html>
<head><title>Using Stored Procedures With Parameters</title></head>
<body>
<form runat="server" method="post">
Enter a State Code:
<asp:Textbox id="txtRegion" runat="server" />
<asp:Button id="btnSubmit" runat="server"
Text="Search" OnClick="Submit" />
<br/><br/>
<asp:DataGrid id="dgOutput" runat="server" />
</form>
</body>
</html>
<script language="c#" runat="server">
private void Submit(object sender, EventArgs e)
{
String strConnection ="Server=224NUMECA;database=Northwind;user id=sa;password=sa";
SqlConnection objConnection = new SqlConnection(strConnection);
SqlCommand objCommand = new SqlCommand("sp_CustomersByState", objConnection);
objCommand.CommandType = CommandType.StoredProcedure;
SqlParameter objParameter = new SqlParameter("@region", SqlDbType.NVarChar, 15);
/* 新建名为@region并声明为nvchar(15)的参数,它与存储过程中的声明相匹配。该版本的构造函数的第二个参数总是system.data.sqlDbType枚举的成员,该枚举有24个成员,表示您可能需要的所有数据类型的。*/
objCommand.Parameters.Add(objParameter);
/* 第二行将参数添加到命令对象的Parameter集合,经常会忘记该操作 */
objParameter.Direction = ParameterDirection.Input;
/* 设置参数对象的Direction属性,以决定它是否会用于将信息传递给存储过程,或接收来自它的信息。ParameterDirection.Input实际上就是该属性的默认值,但是从维护和可读性的观点出发,将它放入代码中是很有帮助的。 */
objParameter.Value = txtRegion.Text;
/* 我们将参数的value属性设置为TxtRegion文本框的文本属性。 */
objConnection.Open();
objConnection.Open(); dgOutput.DataSource = objCommand.ExecuteReader();
dgOutput.DataBind();
objConnection.Close();
}
</script>
- 使用存储过程从web页面传递参数
- ibatis使用存储过程传递参数
- 从.net 程序中传递table 参数个存储过程
- Sql 存储过程传递参数
- springmvc MyBatis 调用Oracle存储过程,使用Map传递参数
- 关于 mysql 存储过程 传递表名作为参数,以及从存储过程返回值的方法
- 不用存储过程一样参数传递
- 分页存储过程之URL参数传递
- 存储过程的参数传递问题
- reportingservice 存储过程传递多值参数
- sqlserver存储过程的参数传递注意事项
- mysql存储过程传递字符串参数
- Oracle存储过程传递数组参数
- SQLSERVER 存储过程传递数组参数
- MySQL存储过程传递中文参数
- JSP页面 参数传递过程 思路 总结!
- Web 页面Flash传递参数综述
- web页面中参数的传递方法
- 编译实验2-源文件(test.cpp)
- 关于 Blog 和 RSS 的全面介绍
- 在ASP.NET中面向对象的编程思想
- 有空聊聊天吧
- Google PR值查询
- 使用存储过程从web页面传递参数
- 数据库CursorType
- 一个ASP.NET的进度条
- 现实是你没有选择
- 关于Asp.Net中的编程实现下载
- Web用户空件的属性中自定义属性的设置和使用
- CreateFileMapping 函数
- 动态载入树 (ASP+数据库)
- 如何得到其它进程的启动命令行参数