Can I get the ID of the data that I just inserted?

前端 未结 1 480
日久生厌
日久生厌 2021-01-27 06:51

So I want to put a product in an order from an user in the database and the query goes as follows:

INSERT INTO [dbo].[Order](UserID, To_Adress, OrderDate, TravelTi

相关标签:
1条回答
  • 2021-01-27 07:15

    Try using the SQL OUTPUT clause:

    INSERT INTO [dbo].[Order](UserID, To_Adress, OrderDate, TravelTime, ItemCount, Status, TotalPrice)
    OUTPUT inserted.ID
    VALUES (1, 'BIKINI BOTTOM', '20191030 15:00:00', '20191030 15:35:00', 1, 'InTheMaking', 7.50
    

    In combination with SqlCommand.ExecuteScalar()

    0 讨论(0)
提交回复
热议问题