gpt4 book ai didi

c# - 如何使用 LINQ TO SQL 检查用户名是否已存在于数据表中

转载 作者:搜寻专家 更新时间:2023-10-30 23:39:06 24 4
gpt4 key购买 nike

我正在使用 Visual Studio C#;

var d = new linqclassDataContext();
var c = new Table();
c.Id =System.Convert.ToInt32(confirmationCode);
c.username = txtUserName.Text;
c.password = txtPaswword.Text;
c.mail = txtMail.Text;
d.Tables.InsertOnSubmit(c);
d.SubmitChanges();

我想检查用户名是否已经在DT中 请帮助...

最佳答案

有多种方法可以做到。您可以使用 Any,如下所示:

if (!d.Tables.Any(t => t.username.Equals(txtUserName.Text)))
{
d.Tables.InsertOnSubmit(c);
d.SubmitChanges();
}

注意:这里不考虑大小写。如果需要,您可以考虑使用 ToLower()ToUpper()

关于c# - 如何使用 LINQ TO SQL 检查用户名是否已存在于数据表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37440776/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com