简体   繁体   English

如何在Visual Studio(C#)中将ASP.NET项目与SQL Server数据库表连接

[英]How to connect ASP.NET project with SQL Server database table in Visual Studio (C#)

I have created simple database table in Visual Studio 2015 called Users and updated it. 我已经在Visual Studio 2015中创建了一个名为Users简单数据库表,并对其进行了更新。

在此处输入图片说明

I want to connect it with my project, so after I fill in my text fields and press 'Sign Up' button, it can get saved to database. 我想将其与我的项目连接,因此在填写文本字段并按“ Sign Up”按钮后,它可以保存到数据库。 I am aware that I'll have to use string connections and other stuff to connect it, but how do I first connect this project with web.config ? 我知道我将必须使用字符串连接和其他东西来连接它,但是如何首先将该项目与web.config连接起来?

在此处输入图片说明

I have seen people dragging this table to Registration form code, so it would automatically create a connection with web-config, but it didn't work for me. 我见过有人将此表拖到“注册”表单代码中,因此它将自动使用web-config创建连接,但对我而言不起作用。

How do I reference my database from web.config correctly ? 如何正确地从web.config引用我的数据库?

Right-click on MyDatabase.mdf and in the properties panel you will see the Connection String. 右键单击MyDatabase.mdf,然后在属性面板中将看到“连接字符串”。 Copy that into the web config in the ConnectionStrings node: 将其复制到ConnectionStrings节点的Web配置中:

  <connectionStrings>
    <add name="MyDatabase" connectionString="[Paste Connection String Here]"/>
  </connectionStrings>

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

相关问题 ASP.NET本地SQL Server数据库C#gridview数据绑定Visual Studio 2013 - ASP.NET local SQL Server database C# gridview data binding Visual Studio 2013 如何使用Visual Studio 2015连接到ASP.NET中的本地SQL Server数据库? - How to connect to a local SQL Server database in ASP.NET using Visual Studio 2015? 如何使用Visual Studio 2013连接到asp.net中的本地SQL Server数据库? - How to connect to a local SQL server database in asp.net using Visual Studio 2013? 无法连接到SQL Server数据库(ASP.NET C#) - Unable to connect to SQL Server Database (ASP.NET C#) ASP.NET C#在SQL Server数据库表中搜索 - ASP.NET C# Search in a SQL Server Database Table 如何在asp.net c#中从SQL Server数据库表中移动下一条/上一条记录 - How to move next/previous record from SQL Server database table in asp.net c# 我是否必须在 Visual Studio 中连接 SQL 服务器数据库才能在 C# 项目中使用它? - Do I have to connect a SQL Server database in Visual Studio to use it in C# project? 使用C#连接到SQL Server 2012数据库(Visual Studio 2012) - Connect to SQL Server 2012 Database with C# (Visual Studio 2012) C#将数据库连接到Visual Studio项目 - C# Connect database to Visual Studio project 通过asp.net和c#连接到另一个网络上的SQL Server数据库 - Connect to a SQL Server database on another network via asp.net and c#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM