Linq 笔记

xiaoxiao2025-02-12  11

查询 if (this.name.Text.Trim() == null || this.name.Text.Trim() == "") { Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('用户名不能为空!');</script>"); this.name.Focus(); return; } if (this.password.Text.Trim() == null || this.password.Text.Trim() == "") { Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('密码不能为空');</script>"); this.password.Focus(); return; } try { NovelDataContext ndc = new NovelDataContext(); string name = this.name.Text.Trim(); string password = this.password.Text.Trim(); var denglu = from lg in ndc.login where lg.name == name && lg.password == password select lg; if (denglu.Count() > 0) { Response.Cookies["UserName"].Value = this.name.Text.Trim(); if (this.CheckBox1.Checked) { Response.Cookies["UserName"].Expires = DateTime.Today.AddDays(12); } Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('恭喜您,登录成功!');window.location='Default.aspx'</script>"); } else { Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('登录失败,用户名或密码错误!');</script>"); } } catch (Exception) { Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('登录失败,请联系管理员!');</script>"); } } 插入 NovelDataContext ndc = new NovelDataContext(); login lg = new login() { name = name.Text.Trim(), password = password.Text.Trim(), tpassword = TextBox1.Text.Trim() }; ndc.login.InsertOnSubmit(lg); ndc.SubmitChanges(); Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('恭喜您,注册成功!');window.location='login.aspx'</script>"); 修改 NovelDataContext ndc = new NovelDataContext(); string name = this.name.Text.Trim(); string tpassword = this.TextBox1.Text.Trim(); string password = this.password.Text.Trim(); var SelectUser = from lg in ndc.login where lg.name == name && lg.tpassword == tpassword select lg; if (SelectUser.Count() > 0) { foreach (var su in SelectUser) { su.password = password; } ndc.SubmitChanges(); 删除 NovelDataContext ndc = new NovelDataContext(); string name = this.name.Text.Trim(); string tpassword = this.TextBox1.Text.Trim(); string password = this.password.Text.Trim(); var SelectUser = from lg in ndc.login where lg.name == name && lg.tpassword == tpassword select lg; if (SelectUser.Count() > 0) { ndc.login.DeleteAllOnSubmit(SelectUser); ndc.SubmitChanges(); } 相关资源:linq教程 linq笔记 linq学习.rar
转载请注明原文地址: https://www.6miu.com/read-5024587.html

最新回复(0)