标题:如何将DataGridView里的数据通过一个按钮导入到Excel表中去?
取消只看楼主
小孔
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2016-2-25
结帖率:100%
已结贴  问题点数:10 回复次数:0 
如何将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");//更新数据库中的表
        }      
    }
}
搜索更多相关主题的帖子: public Excel 如何 
2016-02-26 15:43



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-461961-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.481537 second(s), 9 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved