SQL output使用
来源:互联网 发布:qt select 网络并发 编辑:程序博客网 时间:2024/05/16 08:20
SQL版:
alter proc testguo
(
@cityid int,
@cityname nvarchar(100) output
)
as
select @cityname = city_name from BA_Hot_City where cityid = @cityid
select @cityname
go
declare @cityname nvarchar(100)
exec testguo 1,@cityname output
另一版:
http://news.newhua.com/news1/program_database/2008/113/0811316426BKIG9BIICJ7164832422993IGG8IGJI41BG3AB01I4H9A.html
一直没有找到一种好的方法来引用有返回值的存储过程的方法,使我在添加数据中走了不少的弯路,最近,在查阅了大量的资料之后,终于在微软的一个实例中找到了一种良好的方法。
首先编写好一有返回值的存储过程
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;再自己改一个参数名就可以了.
- SQL output使用
- SQL output使用
- SQL output使用C#常用
- SQL Server中OutPut子句的使用
- 关于在[SQL Server]Store Procedure中使用OUTPUT 游标
- 在SQL Server应用中使用OUTPUT子句
- 在SQL Server应用中使用OUTPUT子句
- sql server2005 存储过程中output 类型的使用
- SQL Server存储过程Return、output参数及使用技巧
- SQL Server存储过程Return、output参数及使用技巧
- SQL Server存储过程Return、output参数及使用技巧
- 在SQL Server应用中使用OUTPUT子句
- SQL 语句中output参数的使用 很实用!
- SQL Server存储过程Return、output参数及使用技巧
- SQL output用法学习心得
- sql中的OUTPUT
- SQL OUTPUT CLUASE
- SQL: output的用法
- 如何确定是否接收用户提交问题的修改
- 如何将多行字符转化为分割的单词
- the account is locked
- 技术人员职业生涯的红色警报
- IT论坛
- SQL output使用
- 对于广大女性,今天可是特别的日子
- 八个提高关键词排名的SEO优化技巧
- hibernate二级缓存原理分析
- SEO之群发和黑链
- 面向对象的设计原则
- 高手 新手都能用到的140个电脑技巧 (转)
- 像Google一样开会
- 专家系统中新的不确定性知识的表示和处理