我想用存储过程写,因为有两个表,要获取对第一个表操作后的ID
存储过程我是这么写的:
CREATE PROCEDURE Add_Soft
(
@Soft_ID int OUTPUT,
@Soft_Big_CategoryID int=NULL)
AS INSERT Soft_Soft
(Soft_Big_CategoryID)
SELECT @Soft_Big_CategoryID
SELECT @Soft_ID = @@IDENTITY---------------
GO
后台代码的编写获取是:
int softid;
SqlParameter outputID = cmd1.Parameters.Add("@Soft_ID",SqlDbType.Int);
outputID.Direction = ParameterDirection.Output;
softid = Convert.ToInt32(outputID.Value);
这样得到的好象不对啊,请教大虾~
存储过程我是这么写的:
CREATE PROCEDURE Add_Soft
(
@Soft_ID int OUTPUT,
@Soft_Big_CategoryID int=NULL)
AS INSERT Soft_Soft
(Soft_Big_CategoryID)
SELECT @Soft_Big_CategoryID
SELECT @Soft_ID = @@IDENTITY---------------
GO
后台代码的编写获取是:
int softid;
SqlParameter outputID = cmd1.Parameters.Add("@Soft_ID",SqlDbType.Int);
outputID.Direction = ParameterDirection.Output;
softid = Convert.ToInt32(outputID.Value);
这样得到的好象不对啊,请教大虾~
INSERT Soft_Soft
(Soft_Big_CategoryID)
SELECT @Soft_ID = @@IDENTITY SELECT @Soft_Big_CategoryID
它说INSERT后不能跟赋值的SELECT
顺序不能调换啊
SqlParameter outputID = cmd1.Parameters.Add("@Soft_ID",SqlDbType.Int);
outputID.Direction = ParameterDirection.Output;cmd1.Parameters.Add("@Soft_Big_CategoryID",123);cmd1.ExecuteNonQuery(); ///??softid = Convert.ToInt32(cmd1.Parameters["@Soft_ID"].Value);
如果要得到返回值,必须先执行存储过程,才能正确获取
辛苦两位了
谢谢