vs2015 连接mysql

//添加MySql.Data.dll 引用

using
MySql.Data.MySqlClient; using System; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { private static String mysqlcon = "Database=yundaclient;Password=abc@123456;User ID=root;server=127.0.0.1;charset=utf8"; private MySqlConnection conn; private MySqlDataAdapter mDataAdapter; public Form1() { String sname = "Hello,Yummy!"; InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { this.button1.Click += new System.EventHandler(this.ShowMessage); conn = new MySqlConnection(mysqlcon); } private void ShowMessage(object sender, EventArgs e) { MessageBox.Show("Hello,world!"); } private void button1_Click(object sender, EventArgs e) { MessageBox.Show("Hello,world123456789!"); } private void button2_Click(object sender, EventArgs e) { try { conn = new MySqlConnection(mysqlcon); mDataAdapter = new MySqlDataAdapter("select * from admin", conn); mDataAdapter.Fill(dataSet1, "Yummy"); dataGridView1.DataSource = dataSet1.Tables["Yummy"]; } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { } } private void chart1_Click(object sender, EventArgs e) { } } }
原文地址:https://www.cnblogs.com/yangxuming/p/8435457.html