如何使用Visual Studio 2017将db2数据库连接到ASP.NET Core

我想创建一个应用程序来从db2数据库中获取值。我正在使用Windows 7和Visual Studio 2017和.NET Core2.1版本。

我已遵循许多教程使用Visual Studio 2017配置db2,但没有成功。

类似的教程:

  1. https://www.ibm.com/developerworks/community/blogs/96960515-2ea1-4391-8170-b0515d08e4da/entry/Creating_Entity_Data_Model_using_IBM_Data_Server_providers_for_Entity_Framework_Core?lang=en

  2. https://www.ibm.com/developerworks/community/blogs/96960515-2ea1-4391-8170-b0515d08e4da/entry/DB2DotnetCore?lang=en

  3. https://www.ibm.com/developerworks/community/blogs/96960515-2ea1-4391-8170-b0515d08e4da/entry/IBM_DB_NET_Provider_for_MS_NET_Core?lang=en

请让我逐步了解db2连接到底需要做什么?

TIA

ilyu1314 回答:如何使用Visual Studio 2017将db2数据库连接到ASP.NET Core

你应该看看小巧的人。

https://dapper-tutorial.net/dapper

Dapper是通过NuGet安装的:https://www.nuget.org/packages/Dapper

PM> Install-Package Dapper

然后像这样使用它

string sqlQuery = "SELECT * FROM yourTable;";
string yourConnectionString = "Server=myAddress:myPortNumber;Database=myDataBase;UID=myUsername;PWD=myPassword"

using (var connection = new DB2Connection(yourConnectionString)
{
    var yourQueryFromDBList = connection.Query(sqlQuery).ToList();
    foreach(var item in yourQueryFromDBList)
    {     
        Console.Writeline(item.toString());
    }
 }

要查找您的连接字符串,请查看 https://www.connectionstrings.com

本文链接:https://www.f2er.com/3085305.html

大家都在问