3
Answers

Get the Identity by ExecuteScalar

rania Magdy

rania Magdy

15y
5.8k
1
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
Answers (3)