I have a problem with Entity Framework in Asp.net. I want to get the Id value whenever I add a record to the SQL database table. How can I do this? Here is my code:
StoredProcedure USE [Sapphiresworld] GO /****** Object: StoredProcedure [dbo].[addProduct] Script Date: 7/4/2018 10:25:41 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER Proc [dbo].[addProduct] @title nvarchar(250), @price nvarchar(50), @unitID int, @date nvarchar(50), @subCategoryID int, @brandID int, @vat int, @discount int, @picture nvarchar(50), @stock int as declare @MyVal int=0 INSERT into [PRODUCT] values (@title, @price , @unitID, @date, @subCategoryID , @brandID , @vat , @discount , @picture , @stock) Set @MyVal = @@IDENTITY Select @MyVal as Val Here is ClsBrand
public string AddBrand(string brandName) { var result = new SapphiresworldEntities().AddBrand(brandName).ToString(); return result; } Code against Save Button
protected void Btnsave_Click(object sender, EventArgs e) { clsBrand nb = new clsBrand(); string nwBran = nb.AddBrand(relig.Text); }