linq中如何解决这个有关问题:Cannot add an entity with a key that is already in use
发布时间:2011-06-24 21:55:23 文章来源:www.iduyao.cn 采编人员:星星草
linq中怎么解决这个问题:Cannot add an entity with a key that is already in use.
错误信息:Cannot add an entity with a key that is already in use.
错误源:App_Web_vvfzwtzj
堆栈跟踪: 在 UserManagerUC.imgBtnSubmit_Click(Object sender, ImageClickEventArgs e) 位置 d:\MyWork\IM\Controls\UserManagerUC.ascx.cs:行号 361
C# code
protected void imgBtnSubmit_Click(object sender, ImageClickEventArgs e)
{
this.DoInit();
try
{
DBIMDataContext IM = (DBIMDataContext)Application["IM"];
try
{
var users = from user in IM.Users
where user.userID == this.txtUserID.Text
select user;
if (users.Count<User>()>0)
{
this.lblFailed.Text = "This user has been existed!";
this.lblFailed.Visible = true;
return;
}
if (string.IsNullOrEmpty(this.txtAddress.Text))
{
this.lblFailed.Visible = true;
this.lblFailed.Text = "Address is empty!";
}
else if (string.IsNullOrEmpty(this.txtCompany.Text))
{
this.lblFailed.Visible = true;
this.lblFailed.Text = "Company is empty!";
}
else if (string.IsNullOrEmpty(this.txtEmail.Text))
{
this.lblFailed.Visible = true;
this.lblFailed.Text = "Email is empty!";
}
else if (string.IsNullOrEmpty(this.txtPassword.Text))
{
this.lblFailed.Visible = true;
this.lblFailed.Text = "Password is empty!";
}
else if (string.IsNullOrEmpty(this.txtTelphone.Text))
{
this.lblFailed.Visible = true;
this.lblFailed.Text = "Telphone is empty!";
}
else
{
User xUser = new User();
xUser.userID = this.txtUserID.Text;
xUser.address = this.txtAddress.Text;
xUser.company = this.txtCompany.Text;
xUser.email = this.txtEmail.Text;
if (string.IsNullOrEmpty(this.txtNickName.Text))
{
xUser.nickName = this.txtUserID.Text;
}
else
{
xUser.nickName = this.txtNickName.Text;
}
xUser.orderFlag = int.Parse(this.ddlOrderFlag.SelectedValue);
xUser.password = this.txtPassword.Text;
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。
其他相似内容:
-
LINQ 方法参数看不懂
怎么我在编译器写代码LINQ方法参数提示看不懂啊,比如 GroupBy(Of TSource, TKey)(IQueryable(Of TSource), E...
-
LINQ 对GridView分页排序处理?
我始终觉得LINQ对gridview分页排序操作很麻烦,请问有什么好的办法啊?还有以前写SQL语句,调试时候很方...
-
Mvc强类型列表如何修改字段
我用这个循环了一个文章列表,但是我要把文章内容字段的html代码给剔除掉,请问怎么做
------解决方案-...
-
Linq查询List<T>无值
List<Wisesoft.Tool.Log.Model.LoginLogInfo> listLog = new List<Wisesoft.Tool.Log.Model.LoginLogInfo>(...
-
SQL中的 is null 在linq中怎么表示
各位大哥,小弟想问下在 sql中的 where coulumn is null这个语句用linq应该怎么写,急用
------...
-
linq + GridView页面数据没有显示
protected void Page_Load(object sender, EventArgs e)
{
//Database db = new...
-
linq to sql 查询的问题,求助
对linq 还不是很熟悉,接触linq了,就有一种冲动要使用它,不用ado了,可是前段时间写一个linq 查询语句的...
-
请教各位 创建SQL server数据库的查询表达式
各位,我那本教程上说,创建一DBML文件,之后什么“创建一个SQL server数据库类型的数据源...
-
类型“System.String[]”不支持比较运算符。
return dc.Content.Where(c => c.Status == status && c.AuditList.Split(',')...
-
请教几个问题linq和数据绑定
1.用vs的O/R设计器生成的Linq to sql 的对象模型会为每个类添加 PropertyChangedEventHandler Prope...