简体   繁体   English

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

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

i am making an online shop mvc web , i made a table for categories and filled it with data , and made a table for products and filled it with data, now how to connect to these database to preview them on web (NOTE: i want to press on store on web , then it will take us to categories then after pressing categories we will have the products in these categories. This is my Store Controller: 我正在制作一个网上商店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

    }
} 

Can you please give me the correct form of connection string to an SQL server 您能给我正确的SQL Server连接字符串形式吗?

Press f12 on OnlineStoreEntities class then check the connectionString mentioned in OnlineStoreEntities :base("connectionstringName") . 在OnlineStoreEntities类上按f12键,然后检查OnlineStoreEntities:base(“ connectionstringName”)中提到的connectionString。 Check the connection string name in webconfig. 在webconfig中检查连接字符串名称。 In web config you can change the connection string values. 在Web配置中,您可以更改连接字符串值。

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

go through this tutorial for DB first approach . 阅读本教程的数据库优先方法。

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

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