12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- using MySql.Data.MySqlClient;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Data.SqlClient;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace WindowsFormsDataSetCopy
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- MySqlConnection conn;
- DataSet ds;
- private void Form1_Load(object sender, EventArgs e)
- {
- conn = new MySqlConnection("server=localhost;database=csharp;uid=root;pwd=abc123");
- MySqlCommand cmd = new MySqlCommand("select * from tb_test", conn);
- MySqlDataAdapter sda = new MySqlDataAdapter();
- sda.SelectCommand = cmd;
- ds = new DataSet();
- sda.Fill(ds, "test");
- dataGridView1.DataSource = ds.Tables[0];
- }
- private void button1_Click(object sender, EventArgs e)
- {
- //复制
- DataSet ds1 = ds.Copy();
- dataGridView2.DataSource = ds1.Tables[0];
- }
- }
- }
|