我使用SQLDataSource
将信息插入数据库。
在插入时,它还会抓取该行的ID
INSERT INTO InkInventory(CodeNumber, InkType, PMS, Color, Description, PoundAvailable, Location, Supplier)
OUTPUT INSERTED.ID
VALUES (@CodeNumber, @InkType, @PMS, @Color, @Description, @PoundsAvailable, @Location, @Supplier)
当我使用查询生成器时,它完美地为我提供了输出,但是如何在我的代码中引用这些结果,在另一个地方使用该数字?
答案 0 :(得分:0)
USE AdventureWorks2012;
GO
--Display the value of LocationID in the last row in the table.
SELECT MAX(LocationID) FROM Production.Location;
GO
INSERT INTO Production.Location (Name, CostRate, Availability, ModifiedDate)
VALUES ('Damaged Goods', 5, 2.5, GETDATE());
GO
SELECT @@IDENTITY AS 'Identity';
GO
--Display the value of LocationID of the newly inserted row.
SELECT MAX(LocationID) FROM Production.Location;
GO