繁体   English   中英

与SQL Server MVC C#的连接字符串

[英]Connection String to an SQL server MVC C#

我正在制作一个网上商店mvc网站,我创建了一个类别表并填充了数据,并创建了产品表并填充了数据,现在如何连接到这些数据库以在Web上预览它们(注意:我想要在网上商店上按,然后将我们带到类别,然后按类别后我们将在这些类别中拥有产品。这是我的商店控制器:

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”)中提到的connectionString。 在webconfig中检查连接字符串名称。 在Web配置中,您可以更改连接字符串值。

https://docs.microsoft.com/en-us/aspnet/mvc/overview/getting-started/database-first-development/creating-the-web-application

阅读本教程的数据库优先方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM