网上有很多例子 但是作者为了简便简化了很多 我上一个完整版的给各位参考
引用using MySQLDriverCS;
代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using MySQLDriverCS;
namespace WindowsFormsApplication12
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
try
{
MySQLConnection con = new MySQLConnection("Password=zxc123123110;User ID=root;Location=localhost;Data Source=user");
con.Open();
DataSet ds = new DataSet();
MySQLDataAdapter adp = new MySQLDataAdapter("select * from user", con);
adp.Fill(ds);
con.Close();
dataGridView1.DataSource = ds.Tables[0];
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
测试图: