lASP.NET使用Linq 时怎么判断插入重复值?
我这样写了一些,应该怎么添加一些上去呢?protectedvoidbtnAdd_Click(objectsender,EventArgse){using(vardb=ne...
我这样写了 一些,应该怎么添加 一些上去呢 ?
protected void btnAdd_Click(object sender, EventArgs e)
{
using (var db=new myDataClassesDataContext())
{
var q = from o in db.UserTable
select o.UserName;
}
if ()
{
}
UserTable u = new UserTable();
u.UserName = txtUserName.Text;
u.UserPwd = txtUserPwd.Text;
u.UserRight = DpLUserRight.Text;
} 展开
protected void btnAdd_Click(object sender, EventArgs e)
{
using (var db=new myDataClassesDataContext())
{
var q = from o in db.UserTable
select o.UserName;
}
if ()
{
}
UserTable u = new UserTable();
u.UserName = txtUserName.Text;
u.UserPwd = txtUserPwd.Text;
u.UserRight = DpLUserRight.Text;
} 展开
1个回答
展开全部
protected void btnAdd_Click(object sender, EventArgs e)
{
using (var db=new myDataClassesDataContext())
{
var q = (from o in db.UserTable
select o.UserName.toarry();
if (!q.contains(txtUserName.Text))
{
UserTable u = new UserTable();
u.UserName = txtUserName.Text;
u.UserPwd = txtUserPwd.Text;
u.UserRight = DpLUserRight.Text;
}
}
}
{
using (var db=new myDataClassesDataContext())
{
var q = (from o in db.UserTable
select o.UserName.toarry();
if (!q.contains(txtUserName.Text))
{
UserTable u = new UserTable();
u.UserName = txtUserName.Text;
u.UserPwd = txtUserPwd.Text;
u.UserRight = DpLUserRight.Text;
}
}
}
追问
if (!q.contains(txtUserName.Text)) 这一句有错 不懂改为什么
追答
if !q.Contains(txtUserName.Text))
额。。。大小写问题
在这之前要判断q!=null
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询