ASP.Net插入数据库没有更新 [英] ASP.Net Insert to database not updating

查看:72
本文介绍了ASP.Net插入数据库没有更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与MSSQL Server 2008的工作,并在它使一个数据库。
现在,我犯了一个ASP.Net(MVC 4)项目,并将其连接到数据库。我让视觉工作室生成实体数据模型和一切工作正常为止。
现在我有一个多对多的关系与ofcourse一个PK,和两个FK的表。当我manualy插入一行来与Microsoft SQL Server Management Studio中的数据库,我刷新我的网页这个新行没有显示出来。

I'm working with MSSQL Server 2008 and made a database in it. Now i made a ASP.Net (MVC 4) project and connected it to the database. I let visual studio generate the Entity Data Model and everything is working fine so far. Now i have a table for a many to many relation with ofcourse a PK, and two FK. When i manualy insert a row to the database with Microsoft SQL Server Management Studio and i refresh my web page this new row doesn't show up.

我100%肯定没有错与C#code(ASP.Net),但X分钟后,该行显示:秒。

I'm 100% sure there is nothing wrong with the C# code (ASP.Net) but after X minutes the row show up :s.

我是否需要更新某个数据源或者我该怎么办错了吗? (这是我的第一个项目ASP.Net:))

Do i need to update the datasource somewhere or what do i do wrong? (it's my first ASP.Net project :))

日Thnx!

code编辑:

private dbEntities db = new dbEntities();

这是dbEntities由Visual Studio从SQL Server生成,其中包含模型中的所有表。

This dbEntities is generated by visual studio from the SQL Server and contains models for all tables.

推荐答案

这听起来像你的数据上下文是陈旧的(它从存储器中检索数据并不会去DB)。

It sounds like your data context is stale (it's retrieving the data from memory and not going to the DB).

请参阅此<一个href=\"http://stackoverflow.com/questions/5462620/entity-framework-data-context-not-in-sync-with-database\">question或本 之一的可能解决方案。

See this question or this one for a possible solution.

编辑:看你的样品code,我要去猜测,这已被宣布为一个页面(或类)成员。你应该在using语句包装这个所以对象范围内可以布置:

Looking at your sample code, I'm going to guess that this has been declared as a page (or class) member. You should wrap this in a using statement so the object context can be disposed:

例如

using (var db = new dbEntities())
{
    //perform work
}

这篇关于ASP.Net插入数据库没有更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆