首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

储存过程的有关问题

2012-01-31 
储存过程的问题//设置参数SqlParameterparamparamcommand.Parameters.Add( @id ,SqlDbType.Int)param

储存过程的问题
//   设置参数
                SqlParameter   param;
                param   =   command.Parameters.Add( "@id ",   SqlDbType.Int);
                param.Direction   =   ParameterDirection.Output;
                param   =   command.Parameters.AddWithValue( "@name ",   idName.Text);
                param.Direction   =   ParameterDirection.Input;
                param.DbType   =   DbType.String;
                param   =   command.Parameters.Add( "@num ",   idNum.Text);
                param.Direction   =   ParameterDirection.Input;
                param.DbType   =   DbType.Int16;
                command.CommandType   =   CommandType.StoredProcedure;
                command.CommandText   =   "spAddOrder ";

                command.ExecuteNonQuery();

                //   获取得到的id
                string   id   =   command.Parameters[ "@id "].Value.ToString();
                Label1.Text   =   "( "   +   id   +   ") ";


插入是成功了
但取不到id值

储存过程
CREATE   PROCEDURE   spAddOrder  
@name   nchar,
@num   integer,
@id   integer   out
as
Insert   into   [cloud]   (   name,   num)   values(@name,   @num);

GO


[解决办法]
begin tran:Insert into [cloud] ( name, num) values(@name, @num);select @@identity as id;commit;
[解决办法]
CREATE PROCEDURE spAddOrder
@name nchar,
@num integer,
@id integer out
as
Insert into [cloud] ( name, num) values(@name, @num);
select @id = @@indentity
GO
[解决办法]
select @id = SCOPE_INDENTITY()
可以保证

热点排行