public int PublishNews(News news)
{
SqlParameter[] param = new SqlParameter[]
{
new SqlParameter("@NewsTitle",news.NewsTitle),
new SqlParameter("@NewsContents",news.NewsContents),
new SqlParameter("@CategoryId",news.CategoryId)
};
using (HotelDBEntities db = new DAL.HotelDBEntities())
{
return db.Database.ExecuteSqlCommand("execute usp_AddNews @NewsTitle,@NewsContents,@CategoryId", param);
}
}
sql脚本:
use HotelDB
go
--发布新闻
if exists (select * from sysobjects where name='usp_AddNews')
drop procedure usp_AddNews
go
create procedure usp_AddNews
@NewsTitle varchar(100),
@NewsContents text,
@CategoryId int
as
insert into News(NewsTitle, NewsContents, CategoryId)
values(@NewsTitle, @NewsContents, @CategoryId)
--得到上一次插入记录时自动产生的ID
select @@IDENTITY
go
if exists (select * from sysobjects where name='usp_ModifyDishes')
drop procedure usp_ModifyDishes
go
create procedure usp_ModifyDishes
@DishesId int,
@DishesName varchar(100),
@UnitPrice numeric(18,2),
@CategoryId int
as
update Dishes set DishesName=@DishesName, UnitPrice=@UnitPrice,
CategoryId=@CategoryId where DishesId=@DishesId
go
create table Dishes --菜品表
(
DishesId int identity(100,1) primary key , --菜品编号
DishesName varchar(100),--菜品名称
UnitPrice numeric(18,2), --价格
CategoryId int references DishesCategory(CategoryId)--分类编号
)
go