[英]Reading data from SQL Server in ASP.NET
Is there any mechanism with which I can easily read data from SQL Server inside a get
routine? 有什么机制可以轻松在
get
例程中从SQL Server读取数据?
Till now I am using my connection string, and sending the query. 到现在为止,我正在使用连接字符串并发送查询。
Web.config
: Web.config
:
<connectionStrings>
<add name="SqlDatabase"
connectionString="yourConnectionString"
providerName="System.Data.SqlClient" />
</connectionStrings>
ASP.NET MVC code: ASP.NET MVC代码:
public IEnumerable<string> Get()
{
var connectionString = WebConfigurationManager.ConnectionStrings["SqlDatabase "].ConnectionString;
SqlConnection connection = new SqlConnection(connectionString);
connection.Open();
}
Is there something easier for reading or writing into SQL Server? 是否可以更轻松地读取或写入SQL Server?
There are more options: 还有更多选择:
1) ADO.NET (Standard open/close connection + data reading) ( https://www.codeproject.com/Articles/4416/Beginners-guide-to-accessing-SQL-Server-through-C ) 1)ADO.NET(标准打开/关闭连接+数据读取)( https://www.codeproject.com/Articles/4416/Beginners-guide-to-accessing-SQL-Server-through-C )
2) ORMs (Entity framework: http://www.entityframeworktutorial.net/code-first/simple-code-first-example.aspx ) 2)ORM(实体框架: http ://www.entityframeworktutorial.net/code-first/simple-code-first-example.aspx)
3) Linq to SQL ( https://www.c-sharpcorner.com/article/an-overview-of-linq-to-sql/ ) 3)Linq到SQL( https://www.c-sharpcorner.com/article/an-overview-of-linq-to-sql/ )
I have created one presentation a few years back but its in Czech unfortunately but from slide 29 there are some code examples. 几年前,我创建了一个演示文稿,但不幸的是,它用捷克语编写,但是从幻灯片29开始,有一些代码示例。 ( https://www.slideshare.net/Vtzslavimon/aspnet-mvc-3-and-sql-server-interoperability-overview-cz )
( https://www.slideshare.net/Vtzslavimon/aspnet-mvc-3-and-sql-server-interoperability-overview-cz )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.