Dears,
I want to Insert row and retrieve the Identity : SqlCommand cmd1 = new SqlCommand( "INSERT INTO SalesTable (ProductId, CustomerId, Qty, SaleDate, SalePrice, SalePolicy, Notes) " + " VALUES (@ProductId, @CustomerId, @Qty, @SaleDate, @SalePrice, @SalePolicy, @Notes)" + " SELECT SCOPE_IDENTITY() ", dbModule.con); each time the execute scaller return Empty (Guid should contain 32 digits .....) I tried many ways with both Scallar and Reader would u plz tell me the write way to code this
Thanks
Get the Identity by ExecuteScalar
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Roei BarRank #1,271 · 1.4K reputationPosted Aug 27, 2009, 1:57 AM EDT
if you are using "uniqueidentifier" then you need to return the inserted newid()
just put the code you wrote directly in SQL Server and you will see the return type
rania Magdy9 reputationPosted Aug 27, 2009, 2:37 AM EDT
Roei BarRank #1,271 · 1.4K reputationPosted Aug 27, 2009, 4:03 AM EDT
Declare @yourNewId Uniqueidentifier
SET @yourNewId = SCOPE_IDENTITY()
return @yourNewId