C#连接mysql

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

using MySql.Data.MySqlClient;

namespace winformtest

{

    public partial class Form2 : Form

    {

        public Form2()

        {

            InitializeComponent();

        }

        private void Form2_Load(object sender, EventArgs e)

        {

            string type = "K34";

            string constr = "server = localhost;User Id = root;password = 123456;Database =XXX ;CharSet=utf8  ";

            MySqlConnection mysql = new MySqlConnection(constr);

            mysql.Open();

            string sql = "select * from XXX";         

            MySqlDataAdapter ada = new MySqlDataAdapter(sql, mysql);

            DataSet ds = new DataSet();

            ada.Fill(ds);

            label1.Text = ds.Tables[0].Rows[0]["个数"].ToString();

            mysql.Close();

        }

    }

}

猜你喜欢

转载自blog.csdn.net/boiled_water123/article/details/81161184