asp.net core connection mysql

Open VS, tools "NuGet Package Manager" NuGet management solution package, and install search MySql.Data

 

 

 

 MySQL code to test the connection:

 


using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using MySql.Data.MySqlClient;

namespace ZZTCore.Controllers
{
public class LoginController : Controller
{
public IActionResult Index()
{
DataTable dt = new DataTable();
DataSet ds = new DataSet();
try
{
using (MySqlConnection con = new MySqlConnection("Data Source=localhost;User ID=root;Password=zt102545;Database=employees;Allow User Variables=True;Charset=utf8;"))
{
if (con.State != ConnectionState.Open)
con.Open();
= New new SDA the MySqlDataAdapter the MySqlDataAdapter ( "SELECT * from the titles", CON);
sda.Fill (DS);
con.Close ();
}
}
the catch (Exception EX)
{
String S = ex.Message;
}
return View ();
}
}
}
----------------
Disclaimer: This article is CSDN bloggers' brake shadow "of the original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
Original link: https: //blog.csdn.net/zt102545/article/details/87919044

Guess you like

Origin www.cnblogs.com/hanshuhe/p/12116100.html