asp.net中C#调用存储过程
创建存储过程:
create procedure houseCount
(
@house_state nvarchar(20),
@house_count int output
)
as
select @house_count=COUNT(*) from house where house_state=@house_state sql执行存储过程:
declare @house_count int
execute houseCount '空房',@house_count output select @house_count
C#调用存储过程:
protected void Page_Load(object sender, EventArgs e)
{
string count_house = ProcedureCount("空房");
Response.Write(string.Format(count_house));
}
//调用存储过程
public string ProcedureCount(string house)
{
string count_house = "";
string strConnection = "user id=sa;password=sa;initial catalog=houseState;Server=127.0.0.1;Connect Timeout=30";
using (SqlConnection conn = new SqlConnection(strConnection))
{
conn.Open();
using (SqlCommand sqlComm = conn.CreateCommand())
{
//设置要调用的存储过程的名称
sqlComm.CommandText = "houseCount";
//指定SqlCommand对象传给数据库的是存储过程的名称而不是sql语句
sqlComm.CommandType = CommandType.StoredProcedure; SqlParameter username = sqlComm.Parameters.Add(new SqlParameter("@house_state", SqlDbType.VarChar, ));
//指明"@username"是输入参数
username.Direction = ParameterDirection.Input;
//为“@username”参数赋值
username.Value =house; SqlParameter password = sqlComm.Parameters.Add(new SqlParameter("@house_count", SqlDbType.Int));
//指定"@password"为输出参数
password.Direction = ParameterDirection.Output;
//执行
sqlComm.ExecuteNonQuery();
//得到输出参数的值,把赋值给name,注意,这里得到的是object类型的,要进行相应的类型轮换
count_house = sqlComm.Parameters["@house_count"].Value.ToString(); }
}
return count_house;
}
asp.net中C#调用存储过程的更多相关文章
- asp.net中怎样调用存储过程和存储过程的写法(转载,留着自己看)
asp.net中怎样调用存储过程和存储过程的写法 创建一个只有输入参数的存储过程 create procedure proc_user@name varchar(20),@Password varch ...
- ASP.net 中手工调用WS(POST方式)
ASP.net 中手工调用WS(POST方式)核心代码:string strUrl="http://localhost:21695/service1.asmx/getmythmod" ...
- asp.net中处理程序调用HttpContext.Current.Session获取值出错
asp.net中处理程序调用System.Web.HttpContext.Current.Session获取Session时提示错误:未将对象引用设置到对象的实例. 解决办法:在处理程序文件类中实现I ...
- 关于MVC 中EF调用存储过程
Entity Framework 4.3 中使用存储过程 分类:ASP.NET MVC 3, ASP.NET 0 尽管 Entit ...
- asp.net中分页与存储过程的一些总结
一.接上文,使用的是jquery AJAX 进行分页 分页存储过程代码如下: ALTER PROCEDURE [dbo].[USP_GetAlbumByPage] @pageIndex int,--当 ...
- asp.net中异步调用webservice
WebService方法是不需要作任何修改的,只是在调用时采用异步的方式,这样在循环中,速度会显得快一点. 原来的方式: HotelMagWeb.com.china_sms.www.MainServi ...
- asp.net中异步调用WebService(异步页)[转]
由于asp2.0提供了异步页的支持使异步调用WebService的性能有了真正的提升.使用异步页,首先要设置Async="true",异步页是在Prerender和Prerende ...
- ASP.NET中前台调用后台的方法
学习文章:http://www.cnblogs.com/kingteach/archive/2010/11/12/1875633.html 练习代码: 前台: <html xmlns=" ...
- asp.net调用存储过程详解
摘要 存储过程的调用在B/S系统中用的很多.传统的调用方法不仅速度慢,而且代码会随着存储过程的增多不断膨胀,难以维护.新的方法在一定程度上解决了这些问题. 关键词 ASP.NET:存储过程 在使用 ...
随机推荐
- opencv cvtColor dtype issue(error: (-215) )
opencv cvtColor dtype issue(error: (-215) ) 更详细的错误信息如下,color.cpp:9710: error: (-215) depth == CV_8U ...
- HDU 1997汉诺塔VII
又是汉诺塔~ 回顾一下汉诺塔的移动过程. 从左到右设为A,B,C 3个盘子的时候 1: No.1 A -> C 2: No.2 A -> B 3: No.1 C -> B 4 ...
- 5、regulator系统的概念及测试
概念:Regulator : 电源芯片, 比如电压转换芯片Consumer : 消费者,使用电源的部件, Regulator是给Consumer供电的machine : 单板,上面焊接有Regulat ...
- 【Codeforces Round #437 (Div. 2) A】Between the Offices
[链接]h在这里写链接 [题意] 在这里写题意 [题解] 在这里写题解 [错的次数] 0 [反思] 在这了写反思 [代码] #include <bits/stdc++.h> using n ...
- IDEA 创建Web项目并在Tomcat中部署运行(转)
原文地址:https://www.cnblogs.com/tufujie/p/5738250.html IDEA 14.0.5 apache-tomcat-8.0.32 步骤:File->New ...
- Java解惑八:很多其它库之谜
本文是依据JAVA解惑这本书,做的笔记. 电子书见:http://download.csdn.net/detail/u010378705/7527721 谜题76 将线程的启动方法start(),写成 ...
- Android CursorAdapter的使用详解
一.CursorAdapter介绍 CursorAdapter这个类是继承于BaseAdapter的它是一个虚类它为Cursor和ListView连接提供了桥梁 二.CursorAdapter详解 1 ...
- 在Excel中粘贴时怎样跳过隐藏行
http://www.excel123.cn/Article/exceljichu/201203/932.html 有时在筛选后需要将其他区域中的连续行数据复制粘贴到筛选区域,以替换筛选后的数据.由于 ...
- [React Native] Animate Styles of a React Native View with Animated.timing
In this lesson we will use Animated.timing to animate the opacity and height of a View in our React ...
- Android定位开发之百度定位、高德定位、腾讯定位,三足鼎立一起为我所用!
这几天的项目不是非常紧.于是想为未来可能要做的项目做一些技术储备. 下一个项目非常有可能是定位开发,须要用到手机定位功能,于是查了查如今比較流行的第三方定位,最火的基本上就是百度定位>高德定位& ...