我有一个数据GridView和我有两个文本框,当我对数据的GridView单击行相应的行值填充在文本框中类别表......试图更新实体
高达这个工作的罚款....
我想更新类别表时,我的保存按钮点击
我有
category_id
category_name
category_description
,这我类别表或许这就是我的代码:
private void btnSave_Click(object sender, EventArgs e)
{
if(dgvCategories.SelectedRows.Count >0)
{
int updatecategoryid = Convert.ToInt32(dgvCategories.SelectedRows[0].Cells[0].Value);
category categoryupdate = new category() { category_Id = updatecategoryid };
categoryupdate.category_Name = tbCategoryName.Text;
categoryupdate.category_Description = tbCategoryDescription.Text;
dbcontext.SaveChanges();
}
}
它不更新栏目表.....
将在此任意一个帮助.....
错误:用空的EntityKey值的对象不能附加到对象上下文。 InvalidoperationException被取消打印。 –
@ user852714:您使用的是什么版本的实体框架? – StriplingWarrior
E.F 1版本... –