zoukankan      html  css  js  c++  java
  • AccessImport demo

    View Code
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Data.OleDb;
    
    namespace AccessImport_v1._0
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            OleDbConnection conn = new OleDbConnection();
            OleDbCommand com = new OleDbCommand();
    
            private void button1_Click(object sender, EventArgs e)
            {
                OpenFileDialog of = new OpenFileDialog();
                of.Filter = "Excel文件|*.xls";
                if (of.ShowDialog() == DialogResult.OK)
                {
                    textBox_ExcelFile.Text = of.FileName;
                }
            }
    
            private void button2_Click(object sender, EventArgs e)
            {
                OpenFileDialog of1 = new OpenFileDialog();
                of1.Filter = "Access文件|*.mdb";
                if (of1.ShowDialog() == DialogResult.OK)
                {
                    textBox_AccessFile.Text = of1.FileName;
                }
            }
    
            public void import()
            {
                try
                {
                    conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + textBox_AccessFile.Text;
                    com.Connection = conn;
                    conn.Open();
                    if (radioButton1.Checked == false)
                    {
                        com.CommandText = "delete from " + textBox_AccessTableName.Text.Trim();
                        com.ExecuteNonQuery();
                    }
                    com.CommandText = "insert into " + textBox_AccessTableName.Text.Trim() + " (" + textBox_AccessField.Text.Trim()
                        + ") select " + textBox_ExcelField.Text.Trim() + " from [Excel 8.0;database="
                        + textBox_ExcelFile.Text.Trim() + "].[sheet1$] ";
                    com.ExecuteNonQuery();
                    MessageBox.Show("Import Success!");
    
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message);
                }
                finally
                {
                    conn.Close();
                }
            }
    
            private void button3_Click(object sender, EventArgs e)
            {
                import();
            }
    
            private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
            {
                about ab = new about();
                ab.ShowDialog();
            }
    
            private void Form1_FormClosing(object sender, FormClosingEventArgs e)
            {
                
                Application.Exit();
            }
    
    
    
    
    
        }
    }
  • 相关阅读:
    Protocol Buffer技术详解(语言规范)
    google protobuf 简单实例
    advStringGrid单元格文字垂直居中
    java中两个字符串如何比较大小
    List集合去除重复对象及equals()、hashCode()方法的作用
    Delphi中使用ActiveX的一些心得
    java List去重方式及效率对比
    Visual Studio Code 调整字体大小
    用最简单的例子实现jQuery图片即时上传
    Linux下绝对经典的命令
  • 原文地址:https://www.cnblogs.com/homchou/p/2838017.html
Copyright © 2011-2022 走看看