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:存储过程 在使用 ...
随机推荐
- jvisualvm 工具使用
VisualVM 是Netbeans的profile子项目,已在JDK6.0 update 7 中自带(java启动时不需要特定参数,监控工具在bin/jvisualvm.exe). https:// ...
- 6.5 Android硬件访问服务使用反射
1.前面的例子中App为了能够范问ILedService接口,把classes.jar导入到应用程序中,但是我们不想把classes编进apk包里面去,这样导致我们的apk程序会很大(解压缩apk会发 ...
- MySQL启动关闭添加到 /etc/init.d/mysqld
cp /data/mysql/support-files/mysql.server /etc/init.d/mysqld 然后就可以使用此命令启动/关闭 mysql: /etc/ini ...
- 21、IIS声卡驱动程序
声卡芯片的数据通道一般都是IIS接口,但是控制音量等控制信息的接口都不相同 (新内核在linux-3.4.2\sound\soc\codecs\uda134x.c) uda134x_codec_pro ...
- [Swift] Add Scroll View
import UIKit class AboutViewController : UIViewController @IBOutlet weak var scrollView: UIScrollVie ...
- 【note】缩写词
CoE CANopen EtherCAT应用程序概要文件CANopen™是一个注冊商标的能够自己主动化汽车集团..纽伦堡.德国CiA402CANopen™驱动器配置文件里指定的IEC 61800-7- ...
- bc -l 对于 %取模计算出错
https://yq.aliyun.com/articles/279384 expr % expr The result of the expression is the "rema ...
- 立足“快时尚”,联想笋尖S90怎样诠释“比美更美”?
现现在."快时尚"已经成为广受年轻人追捧的消费观,从服装界的H&M.ZARA到餐饮界的绿茶.外婆家等等,我们都不难看出,快时尚已成为激发年轻人消费欲望的核心元素,并 ...
- TextView之一:子类的常用属性 分类: H1_ANDROID 2013-10-30 15:14 770人阅读 评论(0) 收藏
TextView常见的子类包括EditText,Button,CheckBox, RadioButton等. 1.EditText EditText继承自TextView,因此TextView所有属性 ...
- 嵌入式linux串口通信自发自收测试程序
/*串口自收自发程序主函数*/#include"uart_api.h"int main(){ int fd; char buff[BUFFER_SIZE]; char buff2 ...