All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
Ajax 及其入门基础(2)_[AJAX教程]
asp.net,2.0中不同web控件之间的相互调用_[Asp.Net教程]
总结asp.net回发或回调参数无效解决方法_[Asp.Net教程]
HTML网页制作基础教程(2):标记的写法_[Html教程]
提高PHP程序运行效率的四个小方法_php资料_编程技术
深入剖析Asp.net资源文件_[Asp.Net教程]
权衡安全和功能,编写安全的Web2.0应用_.net资料_编程技术
如何让你的SQL运行得更快(3)_[SQL,Server教程]
如何用.NET,Array类的Sort方法分类数值_.net资料_编程技术
LINQ体验(15)——LINQ,to,SQL语句之用户定义函数_[Asp.Net教程]
Reading number is top 10 pictures
Summer is most suitable for young people to travel in China1
牛奶和人奶哪个好?
Fan bingbing black wings for platform and DanLuoWang believes beauty1
青春清纯美女大集合1
Fury xp desktop theme
Nikon microscopic photography of the first three
美女
全球清廉国家排行
西游四格漫画(六)
Female model behind the bitterness, often being overcharged3
Download software ranking
Eclipse 4.2.2 For Win32
星际争霸1.08硬盘免安装版
传奇私服架设教程
少妇苏霞全本
卡丁车单机版
c#程序设计案例教程
WebService在.NET中的实战应用教学视频 → 第2集
Tram sex maniac 2 (H) rar bag2
Adobe Flash Player(IE) 10.0.32.18 浏览器专用的FLASH插件
Sora aoi - one of more PK
归海一刀 published in(发表于) 2014/2/1 0:24:00 Edit(编辑)
调用存储过程并且使用返回值的基本方法_[SQL,Server教程]

调用存储过程并且使用返回值的基本方法_[SQL,Server教程]

调用存储过程并且使用返回值的基本方法_[SQL Server教程]

一直没有找到一种好的方法来引用有返回值的存储过程的方法,使我在添加数据中走了不少的弯路,最近,在查阅了大量的资料之后,终于在微软的一个实例中找到了一种良好的方法。
首先编写好一有返回值的存储过程
create procedure proc_name
@para1 nchar(20), --输入参数
@para2 int = null out --输出参数,供程序使用
as
set nocount on
if ( not exists (select * from employee where em_name=@para1))
begin
insert into employee(name) values(@para1)
select @para2=@@identity --返回添加记录的ID
return 1 --返回是否成功添加数据
end
else
return 0 --返回失败
go
然后是调用存储过程的方法
sqlcommand command;
command = new sqlcommand(proc_name,new sqlconnection(connectionstr));
command.paraments.add("@para1"),"name1"); //输入参数,职员姓名
command.paraments.add(new sqlparament("@para2", //生成一输出参数
SqlDbType.Int;             //参数数据类型
ParamenterDirection.OutPut,      //输入输出类型
0,
0,
string.Emplty,
DataRowVerstion.Default,
null)                 //参数值,输入参数时需提供
);
command.commandtype=commandtype.StoredProcedure;
command.connection.open();
command.executenonQuery();
int pkid=(int)command.Parameters["@para2"].value; //得到输出参数的值
command.connection.close();
此处是引用输出参数,如果要引用返回值(是否成功添加数据)则只需把ParamenterDirection的类型改为returnvalue;再自己改一个参数名就可以了.







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.