2015-04-13 86 views
0

我正在使用SQLDataSource将信息插入到数据库中。 虽然它插入它也抓住这一行将输出结果绑定到变量

INSERT INTO InkInventory(CodeNumber, InkType, PMS, Color, Description, PoundAvailable, Location, Supplier) 
OUTPUT INSERTED.ID 
VALUES (@CodeNumber, @InkType, @PMS, @Color, @Description, @PoundsAvailable, @Location, @Supplier) 

当我使用查询生成器它给我的输出完美的ID,但我怎么那么请参考我的代码,这些成果的背后,使用该号码在另一个地方?

回答

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