[英]Reading data from SQL Server in ASP.NET
有什么機制可以輕松在get
例程中從SQL Server讀取數據?
到現在為止,我正在使用連接字符串並發送查詢。
Web.config
:
<connectionStrings>
<add name="SqlDatabase"
connectionString="yourConnectionString"
providerName="System.Data.SqlClient" />
</connectionStrings>
ASP.NET MVC代碼:
public IEnumerable<string> Get()
{
var connectionString = WebConfigurationManager.ConnectionStrings["SqlDatabase "].ConnectionString;
SqlConnection connection = new SqlConnection(connectionString);
connection.Open();
}
是否可以更輕松地讀取或寫入SQL Server?
還有更多選擇:
1)ADO.NET(標准打開/關閉連接+數據讀取)( https://www.codeproject.com/Articles/4416/Beginners-guide-to-accessing-SQL-Server-through-C )
2)ORM(實體框架: http ://www.entityframeworktutorial.net/code-first/simple-code-first-example.aspx)
3)Linq到SQL( https://www.c-sharpcorner.com/article/an-overview-of-linq-to-sql/ )
幾年前,我創建了一個演示文稿,但不幸的是,它用捷克語編寫,但是從幻燈片29開始,有一些代碼示例。 ( https://www.slideshare.net/Vtzslavimon/aspnet-mvc-3-and-sql-server-interoperability-overview-cz )
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.