这是我的存储过程:
BEGIN
SET NOCOUNT ON;
INSERT INTO [dbo].[KYS_CustomerComplaints] (
CustomerId
,UserId
,STATE
,Address
,PhoneNumber
,Email
,StorageCondition
,OtherConditions
,ProductId
,ProductAmount
,LOTNo
,HandBill
,CallingBill
,ProductionDate
,ExpirationDate
,CreatedDate
,LastEditionDate
,LastEdited_UserId
,Code
)
VALUES (
@CustomerId
,@UserId
,@State
,@Address
,@PhoneNumber
,@Email
,@StorageCondition
,@OtherConditions
,@ProductId
,@ProductAmount
,@LOTNo
,@HandBill
,@CallingBill
,@ProductionDate
,@ExpirationDate
,@CreatedDate
,@LastEditionDate
,@LastEdited_UserId
,@Code
)
DECLARE @new_identity INT;
SELECT @new_identity = SCOPE_IDENTITY()
RETURN @new_identity;
END
如何提供输出ID?
var parameters = new[]
{
new SqlParameter("@CustomerId",customer.CustomerId ),
new SqlParameter("@UserId",customer.UserId),
new SqlParameter("@State",customer.State ),
new SqlParameter("@Address",customer.Address ),
new SqlParameter("@PhoneNumber",customer.PhoneNumber ),
new SqlParameter("@Email",customer.Email ),
new SqlParameter("@StorageCondition",customer.StorageCondition ),
new SqlParameter("@OtherConditions",customer.OtherConditions ),
new SqlParameter("@ProductId",customer.ProductId ),
new SqlParameter("@ProductAmount",customer.ProductAmount ),
new SqlParameter("@LOTNo",customer.LOTNo ),
new SqlParameter("@HandBill",customer.HandBill ),
new SqlParameter("@CallingBill",customer.CallingBill ),
new SqlParameter("@ProductionDate",customer.ProductionDate ),
new SqlParameter("@ExpirationDate",customer.ExpirationDate ),
new SqlParameter("@CreatedDate",customer.CreatedDate ),
new SqlParameter("@LastEditionDate",customer.LastEditionDate ),
new SqlParameter("@LastEdited_UserId",customer.LastEdited_UserId ),
new SqlParameter("@Code",customer.Code ),
};
var model = AdoNetHelper.ExecuteSql(ProcType.Scalar, ReturnType.DataSet, "CRM_CustomerComplaint_Add", parameters);
return "Başarıyla Eklendi";
答案 0 :(得分:0)
第一种方法:添加这样的输出参数
create procedure myStoredProc(@input1 int, ..., @NewIdentity int output)
as
begin
set nocount on;
insert into KYS_CustomerComplaints(...) values (...);
SELECT @NewIdentity = SCOPE_IDENTITY();
end
第二种方法:让过程返回这样的值
create procedure myStoredProc(@input1 int, ...)
as
begin
set nocount on;
insert into KYS_CustomerComplaints(...) values (...);
SELECT SCOPE_IDENTITY();
end
在您的情况下,return
语句没有用。