添加實體數據模型 下一步 下一步 添加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 = "[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();//保存到資料庫 } } }