EF练习
程序员文章站
2022-06-24 13:13:47
添加实体数据模型 下一步 下一步 添加web窗体 简单添加一个操作按钮 ......
添加实体数据模型
下一步
下一步
添加web窗体
<body> <form id="form1" runat="server"> <div> <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /> </div> </form> </body>
简单添加一个操作按钮
namespace WebApplication1 { public partial class WebForm1 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { familySafetyFirecontrolSystemEntities context = new familySafetyFirecontrolSystemEntities(); TbUser user = new TbUser(); user.UserID = "001"; user.UserEmail = "xy@123.com"; user.UserName = "xy"; user.UserPassword = "123456"; user.UserPhone = "12345678901"; user.UserTypeID = "1"; context.TbUser.Add(user);//增加 // context.Entry<TbUser>(user).State = System.Data.EntityState.Added;//增加 // context.Entry<TbUser>(user).State = System.Data.EntityState.Deleted;//删除 // context.Entry<TbUser>(user).State = System.Data.EntityState.Modified//修改 context.SaveChanges();//保存到数据库 } } }