创建存储过程:

 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#调用存储过程的更多相关文章

  1. asp.net中怎样调用存储过程和存储过程的写法(转载,留着自己看)

    asp.net中怎样调用存储过程和存储过程的写法 创建一个只有输入参数的存储过程 create procedure proc_user@name varchar(20),@Password varch ...

  2. ASP.net 中手工调用WS(POST方式)

    ASP.net 中手工调用WS(POST方式)核心代码:string strUrl="http://localhost:21695/service1.asmx/getmythmod" ...

  3. asp.net中处理程序调用HttpContext.Current.Session获取值出错

    asp.net中处理程序调用System.Web.HttpContext.Current.Session获取Session时提示错误:未将对象引用设置到对象的实例. 解决办法:在处理程序文件类中实现I ...

  4. 关于MVC 中EF调用存储过程

    Entity Framework 4.3 中使用存储过程 分类:ASP.NET MVC 3, ASP.NET                  0                   尽管 Entit ...

  5. asp.net中分页与存储过程的一些总结

    一.接上文,使用的是jquery AJAX 进行分页 分页存储过程代码如下: ALTER PROCEDURE [dbo].[USP_GetAlbumByPage] @pageIndex int,--当 ...

  6. asp.net中异步调用webservice

    WebService方法是不需要作任何修改的,只是在调用时采用异步的方式,这样在循环中,速度会显得快一点. 原来的方式: HotelMagWeb.com.china_sms.www.MainServi ...

  7. asp.net中异步调用WebService(异步页)[转]

    由于asp2.0提供了异步页的支持使异步调用WebService的性能有了真正的提升.使用异步页,首先要设置Async="true",异步页是在Prerender和Prerende ...

  8. ASP.NET中前台调用后台的方法

    学习文章:http://www.cnblogs.com/kingteach/archive/2010/11/12/1875633.html 练习代码: 前台: <html xmlns=" ...

  9. asp.net调用存储过程详解

    摘要 存储过程的调用在B/S系统中用的很多.传统的调用方法不仅速度慢,而且代码会随着存储过程的增多不断膨胀,难以维护.新的方法在一定程度上解决了这些问题. 关键词 ASP.NET:存储过程   在使用 ...

随机推荐

  1. 第三方插件将数据转成json

    1.需要使用第三方jar commons-beanutils-1.7.0.jar /commons-collections-3.1.jar/commons-lang-2.5jar /commons-l ...

  2. svg的世界、视窗、视野

    刚学svg时 看视频有人说了视窗和视野两个概念.学移动端时,又听说过视口这个概念.感觉还是有点绕的.以此博客来整理记录我查的资料. 1.世界 就是说svg的世界其实可以无限大,你想让它多大就多大,你可 ...

  3. POJ 1679 The Unique 次最小生成树 MST

    http://poj.org/problem?id=1679 题目大意: 给你一些点,判断MST(最小生成树)是否唯一. 思路: 以前做过这题,不过写的是O(n^3)的,今天学了一招O(n^2)的,哈 ...

  4. POJ 2752 Seek the Name, Seek the Fame (KMP)

    传送门 http://poj.org/problem?id=2752 题目大意:求既是前缀又是后缀的前缀的可能的长度.. 同样是KMP,和 HDU 2594 Simpsons' Hidden Tale ...

  5. 博客已迁移至http://blog.csdn.net/lujinhong2/

    http://blog.csdn.net/lujinhong2/ 请继续关注

  6. vc弹出USB的方法. 附试验通过的代码!

    vc弹出USB的方法. 附试验通过的代码! http://blog.sina.com.cn/s/blog_4fcd1ea30100qrzn.html (2011-04-15 10:09:48) boo ...

  7. 无法顺利删除问题处理一则-ORA-00604和ORA-00942错误

    1.以sys/oracle登录 2. -- Create tablecreate table ARGUMENT$(  OBJ#          NUMBER not null,  PROCEDURE ...

  8. 经验总结56--mybatis返回主键

    使用mybatis框架时,有时候须要新插入的数据的主键是多少. 1.oracle 因为oracle是建的序列文件,获取ID值. <insert id="insert" par ...

  9. 在Eclipse中运行Nutch2.3 分类: H3_NUTCH 2015-01-28 16:41 3175人阅读 评论(13) 收藏

    参考http://wiki.apache.org/nutch/RunNutchInEclipse 一.环境准备 1.下载nutch2.3源代码 wget http://mirror.bit.edu.c ...

  10. angular的学习参考材料

    原文地址:https://www.jianshu.com/p/b9db7bb3d4ec 目的 其实写这篇文章的主要目的是为了提供给那些刚刚入门angular或者有意学习angular的读者准备的. 我 ...