COPY表1到表2(结构相同)

 DataTable table;      
        private SqlDataAdapter dataAdapter;
        string connectionString = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=test;Data Source=.";       

        private void de3_Load(object sender, EventArgs e)
        {
            dataAdapter = new SqlDataAdapter("select * from Powerss", connectionString);//空表
            SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);
            table = new DataTable();
            dataAdapter.Fill(table);
            dataGridView1.DataSource = table;//提示作用

        }

        //保存
        private void button3_Click(object sender, EventArgs e)
        {            
           SqlDataAdapter da = new SqlDataAdapter("select * from Powers", connectionString);
            SqlCommandBuilder commandBuilder = new SqlCommandBuilder(da);//这句很重要
            DataSet ds_xls = new DataSet();
            da.Fill(ds_xls);

            DataTable dt = ds_xls.Tables[0];
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                table.Rows.Add(dt.Rows[i].ItemArray);
                Application.DoEvents();
            }
            dataAdapter.Update(table);//在此处更新数据   
            MessageBox.Show("提示操作成功。");
        }

 

可应用在表的导入,只是导入(添加新数据),修改还在搞,自己关注中

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值