添加实体数据模型
下一步
下一步
添加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 = "[email protected]"; 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();//保存到数据库 } } }