gpt4 book ai didi

asp.net - 将 ASP.NET MVC 应用程序连接到 MySQL

转载 作者:行者123 更新时间:2023-11-29 02:06:25 27 4
gpt4 key购买 nike

如何将我的 ASP.NET MVC 应用程序指向 MySQL 数据库?

最佳答案

一旦你download the MySQL ADO.NET Connector在您的项目中引用程序集并编写查询是一件简单的事情,就像您在任何其他应用程序中所做的一样,没有特定的 MVC:

using (var connection = new MySqlConnection(ConnectionString))
using (var cmd = connection.CreateCommand())
{
connection.Open();
cmd.CommandText = "SELECT name FROM foo;";
using (var reader = cmd.ExecuteReader())
{
while (reader.Read())
{
string name = reader.GetString(reader.GetOrdinal("name"));
// TODO: do something with the name ...
}
}
}

关于asp.net - 将 ASP.NET MVC 应用程序连接到 MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5154183/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com