易截截图软件、单文件、免安装、纯绿色、仅160KB

在c#中的取得sql存储过程的output参数

一直没有找到一种好的方法来引用有返回值的存储过程的方法,使我在添加数据中走了不少的弯路,最近,在查阅了大量的资料之后,终于在微软的一个实例中找到了一种良好的方法。
首先编写好一有返回值的存储过程
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();
此处是引用输出参数,如果要引用返回值(是否成功添加数据)则只需把ParamenterDirec


相关文档:

SQL Server Mobile 学习(一):环境搭建

1.SQL Server Mobile 简介
2.获取 SQL Server Mobile
3.安装必备软件
4.安装开发环境
5.安装服务器环境
6.配置 Web 同步向导
7.使用 Internet Explorer 检查 SQL Server Mobile 服务器代理配置
8.使用SQL Server Mobile 数据库
==========================
1.SQL Server Mobile 简介
-------------------------- ......

实现多行合并一行的SQL写法

[ORACLE]
项目中遇到一个需求,需要将多行合并为一行。
表结构如下:
NAME                            Null           ......

sql server 2000 数据表的 关键字

create table "user" (
   id                   int                  identity,
   constraint PK_USER prim ......

sql server 索引入门

    最近做了一网站,但是在外面访问太慢。本想找下原因。看看是程序原因还是数据库原因。在网上逛逛。看了一下数据库索引。现在总结一下。方便下次查看。本文比较基础是入门级别的。
     首先,什么是索引?从BookOnline上search了一下:    
  &nbs ......

sql:存储过程,事务,out参数

CREATE proc [dbo].[proc_DeleteTemplet] (@templeId varchar(15),@errorMessage varchar(50) output)
as
begin
  declare @error int
  set @error =0
  begin tran
  delete from tc_templet_Head where fBillNo=@templeId
  set @error=@error+@@error
  delete from tc_templet_ ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号