我在 Asp.net 中遇到实体框架问题。每当我向 SQL 数据库表添加记录时,我都想获取 Id 值。我怎样才能做到这一点?这是我的代码:
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
这里是 ClsBrand
public string AddBrand(string brandName)
{
var result = new SapphiresworldEntities().AddBrand(brandName).ToString();
return result;
}
针对保存按钮的代码
protected void Btnsave_Click(object sender, EventArgs e)
{
clsBrand nb = new clsBrand();
string nwBran = nb.AddBrand(relig.Text);
}
慕哥9229398
相关分类