asp.net - 我怎样才能找回这个?
问题描述
这是我的存储过程:
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";
解决方案
第一种方法:像这样添加一个输出参数
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
在您的情况下,声明没有用处。
在这里
使用 C# 中的存储过程输出参数
推荐阅读
- extjs - 在同一事件上绑定 keyMap,但使用 CTRL 且没有 CTRL
- python - 变量的默认值
- ant - 想要热部署我更改的每个文件,而不是使用 ant 执行构建部署
- selenium - webdriver-manager 不被识别为内部或外部命令,尽管我在全球范围内安装了量角器(Jenkins)
- appcelerator - Appcelerator 看不到设备是 iPad 吗?发生了什么?
- python - 如何以编程方式运行/调用烧瓶 cli 命令?
- angular - PrimeNG 复选框默认不被选中
- macros - 如何使来自外部 crate 的宏中的 Rust 警告静音?
- excel - 集中维护excel公式
- graph - Spring Data ArangoDB 直接使用注解获取父级