Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# SQL server MVC的连接字符串#_C#_Asp.net_Sql Server_Database_Asp.net Mvc 4 - Fatal编程技术网

C# SQL server MVC的连接字符串#

C# SQL server MVC的连接字符串#,c#,asp.net,sql-server,database,asp.net-mvc-4,C#,Asp.net,Sql Server,Database,Asp.net Mvc 4,我正在制作一个在线商店mvc网站,我制作了一个分类表并填入数据,制作了一个产品表并填入数据,现在如何连接到这些数据库以在网站上预览它们(注:我想按网上商店,然后它会带我们到类别,然后按类别后,我们将有这些类别的产品。 这是我的商店管理员: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using MVCOnlineShop.Mod

我正在制作一个在线商店mvc网站,我制作了一个分类表并填入数据,制作了一个产品表并填入数据,现在如何连接到这些数据库以在网站上预览它们(注:我想按网上商店,然后它会带我们到类别,然后按类别后,我们将有这些类别的产品。 这是我的商店管理员:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MVCOnlineShop.Models;

namespace MVCOnlineShop.Controllers
{
    public class StoreController : Controller
    {
        OnlineStoreEntities storeDB = new OnlineStoreEntities();
        //
        // GET: /Store/

        public ActionResult Index()
        {
            var Categories = storeDB.Categories.ToList();
            return View(Categories);
        }
        //
        // GET: /Store/Browse
        public ActionResult Browse(string Category)
        {
            // Retrieve Category and its Associated Products from database
            var CategoryModel = storeDB.Categories.Include("Products")
                .Single(g => g.Name == Category);

            return View(CategoryModel);
        }
        //
        // GET: /Store/Details
        public ActionResult Details(int id)
        {
            var Product = storeDB.Products.Find(id);

            return View(Product);
        }
        //
        // GET: /Store/Browse?Category=Games

    }
} 

您能给我一个SQL server连接字符串的正确形式吗?按OnlineStoreEntities类上的f12键,然后检查OnlineStoreEntities:base(“connectionstringName”)中提到的连接字符串。 检查webconfig中的连接字符串名称。 在web配置中,可以更改连接字符串值


对于DB-first方法,请仔细阅读本教程。

您必须使用实体框架,对吗?您提供了连接&全部。我想您不必担心连接。是否应该使用任何代码来连接表中的这些数据?否当您在项目中添加edmx时,您提供了连接字符串并连接到DB,然后您可以在项目中添加实体(表)。我在VS中填写了我的表,然后在sql 1类别中与许多产品建立了关系,现在如何在web上预览它们?(注意:我想按网上商店,然后它将带我们到类别,然后按类别后,我们将拥有这些类别中的产品)我想你应该仔细阅读这篇文章。要在web配置中编写什么来连接到我的sql server?我必须在sql上导入数据库吗?因为我看到了一个关于在app_data.mdf文件中添加的教程,这个.mdf来自于在sql中导入数据库?按照本教程,应用DB-first方法。在app_数据中,我在哪里可以找到.mdf文件?p请阅读本教程,您必须创建一个.mdf文件