如何将DataGridView里的数据通过一个按钮导入到Excel表中去?
这个是我前面的代码和窗口,然后想通过Excel键将DataGridView里的数据导入到Excel表中去。using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace 表格处理
{
public partial class Form1 : Form
{
OleDbConnection conn = new OleDbConnection();
OleDbCommand comm = new OleDbCommand();
OleDbDataAdapter adapter = new OleDbDataAdapter();
DataSet ds = new DataSet();
public Form1()
{
InitializeComponent();
conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=studentinfo.mdb";
comm.Connection = conn;
= "select * from studentinfo where 分数>75";
adapter.SelectCommand = comm;
OleDbCommandBuilder builder = new OleDbCommandBuilder(adapter);//处理的新表放在了adapter中
}
private void button1_Click(object sender, EventArgs e)
{
ds.Clear();
adapter.Fill(ds, "good");//现在将adapter中的表以good名称填到ds中
d1.DataSource = ds.Tables["good"];//d1中即将呈现的是新表good
}
private void button2_Click(object sender, EventArgs e)
{
adapter.Update(ds, "good");//更新数据库中的表
}
}
}