2011-06-02 184 views
2

enter image description here我正在使用mvc3在.net 4.0中設計一個項目。我使用了兩個屬性namefname(父名)。數據存儲在哪裏?

我的控制器類:

loginController.cs

using System; 
using System.Collections.Generic; 
using System.Data; 
using System.Data.Entity; 
using System.Linq; 
using System.Web; 
using System.Web.Mvc; 
using MvcMovie.Models; 

namespace MvcMovie.Controllers 
{ 
    public class loginController : Controller 
    { 
     private logindata db = new logindata(); 

     // 
     // GET: /login/ 

     public ViewResult Index() 
     { 
      return View(db.loginobj.ToList()); 
     } 

     // 
     // GET: /login/Details/5 

     public ViewResult Details(int id) 
     { 
      // login login = db.loginobj.Find(id); 
      login login = db.loginobj.Find(2) ; 
      return View(login); 
     } 

     // 
     // GET: /login/Create 

     public ActionResult Create() 
     { 
      return View(); 
     } 

     // 
     // POST: /login/Create 

     [HttpPost] 
     public ActionResult Create(login login) 
     { 
      if (ModelState.IsValid) 
      { 
       db.loginobj.Add(login); 
       db.SaveChanges(); 
       return RedirectToAction("Index"); 
      } 

      return View(login); 
     } 

     // 
     // GET: /login/Edit/5 

     protected override void Dispose(bool disposing) 
     { 
      db.Dispose(); 
      base.Dispose(disposing); 
     } 
    } 
} 

模型類

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Data.Entity; 
login.cs 

namespace MvcMovie.Models 
{ 
    public class login 
    { 
     public int ID { get; set; } 
     public string name{get; set;} 
     public string fname { get; set; } 
    } 
    public class logindata : DbContext 
    { 
     public DbSet<login> loginobj { get; set; } 
    } 
} 

view.cshtml

@model IEnumerable<MvcMovie.Models.login> 

@{ 
    ViewBag.Title = "Index"; 
} 

<h2>Index</h2> 

<p> 
    @Html.ActionLink("Create New", "Create") 
</p> 
<table> 
    <tr> 
     <th> 
      name 
     </th> 
     <th> 
      fname 
     </th> 
     <th></th> 
    </tr> 

@foreach (var item in Model) { 
    <tr> 
     <td> 
      @Html.DisplayFor(modelItem => item.name) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.fname) 
     </td> 
     <td> 
      @Html.ActionLink("Edit", "Edit", new { id=item.ID }) | 
      @Html.ActionLink("Details", "Details", new { id=item.ID }) | 
      @Html.ActionLink("Delete", "Delete", new { id=item.ID }) 
     </td> 
    </tr> 
} 

</table> 

我想問的是其中存儲的數據這是由我創建?意味着我如何看到由我完成的條目表?

只要我點擊.sdf文件,然後出現如下圖所示的問題,我該如何解決這個問題。我應該安裝一些東西。我安裝了Visual Studio 2010和SQL Server 2008

+1

Pushpendra - 無需三倍複製相同的註釋:)一個簡單的谷歌搜索「這不是一個有效的SQL Server Compact數據庫文件或文件版本不受當前SQL Server Compact Engine支持「作爲_very first_結果將我們帶入解決方案:http://stackoverflow.com/questions/4070860/sql-compact-4-0-cant-open-read-sdf -file – 2011-06-02 05:41:35

回答

4

可能您正在使用Microsoft SQL CE來存儲您的應用程序數據。如果是這種情況,請查看解決方案資源管理器中的App_Data文件夾。你應該看到一個擴展名爲.sdf的文件。只需確保在解決方案資源管理器中選擇顯示所有文件圖標。更多詳情here

enter image description here

enter image description here

+0

先生,無論何時我點擊.sdf文件,都會出現此錯誤「這不是有效的SQL Server Compact數據庫文件,或者當前的SQL Server Compact Engine不支持此文件版本「請建議我該怎麼做。」 – 2011-06-02 02:29:34

+0

選中此項:http://stackoverflow.com/questions/4070860/sql-compact-4-0-cant-open-read-sdf-file - 所以,我認爲您必須安裝Visual Studio SP1才能在Visual Studio中獲得對SQL CE 4的工具支持,請在此處下載它:http://www.microsoft.com/downloads/en/details.aspx?FamilyID=75568aa6-8107-475d-948a -ef22627e57a5 – 2011-06-02 02:32:38

0

它看起來像它通過

私人logindata DB做=新 logindata();

你有詳細的部分嗎?

+0

先生,無論何時單擊.sdf文件,都會發生此錯誤「這不是有效的SQL Server Compact數據庫文件,或者當前SQL Server Compact Engine不支持此文件版本。」請告訴我該怎麼做。 – 2011-06-02 02:34:14

0

logindata DBContext看起來像它是由實體框架創建的。這是指向某個數據庫的地方,那個數據庫就是你要去查找數據的地方。您可以在web.config中查找具有數據庫信息的連接字符串,或者您的項目中有一個.edmx文件,可以打開該文件並查看其指向的內容。

+0

先生,只要我點擊.sdf文件,就會出現此錯誤「這不是有效的SQL Server Compact數據庫文件,或者當前SQL Server Compact Engine不支持此文件版本。「請建議我該怎麼辦?」 – 2011-06-02 02:33:40