zoukankan      html  css  js  c++  java
  • asp.net core 连接mysql

    打开VS,工具》NuGet包管理器》管理解决方案的NuGet程序包,搜索MySql.Data并安装

     测试连接MySQL的代码:


    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();
    MySqlDataAdapter sda = new MySqlDataAdapter("select * from titles", con);
    sda.Fill(ds);
    con.Close();
    }
    }
    catch (Exception ex)
    {
    string s = ex.Message;
    }
    return View();
    }
    }
    }
    ————————————————
    版权声明:本文为CSDN博主「刹影」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/zt102545/article/details/87919044

  • 相关阅读:
    了解Cgroup资源配置方法
    了解Harbor私有仓库创建
    Docker私有部署和管理
    Docker构建镜像实例
    Docker镜像的构建方式
    Docker基本管理
    将列表的元素去重
    python打印出txt中的汉字
    join字符串拼接
    %s占位符 format
  • 原文地址:https://www.cnblogs.com/hanshuhe/p/12116100.html
Copyright © 2011-2022 走看看