【发布时间】:2026-01-01 13:15:01
【问题描述】:
您好,我使用此查询更新我的数据库,但无法正常工作:
if (Request["mode"] != null)
{
Int32 ID = Int32.Parse(Request["Id"].ToString());
using (NoavaranModel.NoavaranEntities1 dbContext = new NoavaranModel.NoavaranEntities1())
{
var ToEdit = (from n in dbContext.Packages
where n.Id == ID
select n).FirstOrDefault();
ToEdit.Name = txtName.Text;
ToEdit.Level = txtLevel.Text;
ToEdit.Description = txtDescription.Text;
ToEdit.ForAge = ddlAgeFor.SelectedItem.Text;
ToEdit.CatId = ddlCategory.SelectedIndex + 1;
dbContext.SaveChanges();
//Response.Redirect("Packages.aspx");
//return;*/
}
}
【问题讨论】:
-
define 不工作,是不是出错了?
-
@Luke McGregor 这不是任何错误。
-
这是我的建议:提供有关该问题的更多信息。或者,在发布之前收集更多信息。
-
我看不出代码本身有问题,所以最好的办法是检查与数据库本身的连接。确保你的连接字符串是正确的,并且先看看 EFProfiler 发生了什么
-
@Luke McGregor 我的数据库连接字符串是正确的。
标签: asp.net entity-framework ef-database-first