Convert Excel data to MDB file
所需组件:
microsoft ado ext. 2.8 for ddl and security 或者更新的组件。
添加:
using ADOX;
using System.Runtime.InteropServices;
using System.IO;
然后利用OleDbCommand组件,设置其2个链接,一个链接负责查找并打开excel数据源,另一个链接负责将数据源插入到MDB文件中。
操作页面:

后台源码:
private void button1_Click(object sender, EventArgs e)
{
var MDbPath = this.txtMDBPath.Text; if (File.Exists(MDbPath) == false)
{
ADOX.Catalog catalog = new ADOX.Catalog(); dynamic cn = null; try
{
cn = catalog.Create(string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};", MDbPath));
}
finally
{
if (cn != null)
{
Marshal.FinalReleaseComObject(cn);
}
Marshal.FinalReleaseComObject(catalog);
} string excelPath = this.txtExcelPath.Text;
string excelConnection = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=\"Excel 8.0;HDR=YES\"", excelPath); using (System.Data.OleDb.OleDbConnection AccessConn = new System.Data.OleDb.OleDbConnection(excelConnection))
{
AccessConn.Open(); string insertCommandText = string.Format("SELECT * INTO [MS Access;DATABASE={0}].[Sheet1] from [Sheet1$];", MDbPath); using (System.Data.OleDb.OleDbCommand AccessCommand = new System.Data.OleDb.OleDbCommand(insertCommandText, AccessConn))
{
AccessCommand.ExecuteNonQuery();
}
AccessConn.Close();
}
}
MessageBox.Show("数据写入成功。");
}
注意:insertCommandText中数据源链接部分必须写:DATABASE=...,不能写Data Source=...,否则会出现“表已经存在”的异常。
Convert Excel data to MDB file的更多相关文章
- Import Data from *.xlsx file to DB Table through OAF page(转)
Use Poi.jar Import Data from *.xlsx file to DB Table through OAF page Use Jxl.jar Import Data from ...
- excel 导入数据库 / SSIS 中 excel data source --64位excel 版本不支持-- solution
当本地安装的excel(2013版) 是64-bit时:出现的以下两种错误 解决: 1. excel 导入数据库 , 如果文件是2007则会出现:“The 'Microsoft.ACE.OLEDB.1 ...
- 读Avoiding the Disk Bottleneck in the Data Domain Deduplication File System
最近在思考和实践怎样应用重复数据删除技术到云存储服务中.找了些论文来读,其中<Avoiding the Disk Bottleneck in the Data Domain Deduplicat ...
- Microsoft Office Excel cannot access the file, There are several possible reasons
今天在做EXCEL打印读取模板时报错了,错误信息如下: Microsoft Excel cannot access the file 'D:\xx.xlsx'. There are several p ...
- ORA-01578 ORACLE data block corrupted (file # 29, block # 2889087)
BW数据库后台报错如下:F:\oracle\SBP\saptrace\diag\rdbms\sbp\sbp\trace ORA-01578: ORACLE data block corrupted ( ...
- excel cannot access the file there are several possible reasons
original link Microsoft Office Excel cannot access the file ‘c:\file.xlsx’. There are several possib ...
- ORA-01578: ORACLE data block corrupted (file # 3, block # 1675)
警告日志中发现如下报错信息: ORA-01578: ORACLE data block corrupted (file # 3, block # 1675)ORA-01110: data file 3 ...
- python编辑已存在的excel坑: BadZipFile: File is not a zip file
背景-原代码如下,期望能自动创建excel,并且可以反复调用编辑: import xlwt,osfrom openpyxl.styles import Font, colors class Write ...
- Android App data write as file data with synchronous Demo
package com.android.utils; import java.io.File; import java.io.IOException; import java.io.RandomAcc ...
随机推荐
- 快速上手RaphaelJS--Instant RaphaelJS Starter翻译(二)
(目前发现一些文章被盗用的情况,我们将在每篇文章前面添加原文地址,本文源地址:http://www.cnblogs.com/idealer3d/p/Instant_RaphaelJS_Starter2 ...
- Mac 配置Spark环境scala+python版本(Spark1.6.0)
1. 从官网下载Spark安装包,解压到自己的安装目录下(默认已经安装好JDK,JDK安装可自行查找): spark官网:http://spark.apache.org/downloads.html ...
- 安装Nginx的Dockerfile实例
#################################################Dockerfile to build Nginx Installed Containers##Bas ...
- ubuntu kylin 16.04系统的基本安装
系统版本:ubuntu kylin 16.04 硬件状况:500G HDD+120G SSD 已安装操作系统:WIN 10专业版(craked) ——WIN 10系统是装在SSD的第一个盘符内的.以前 ...
- install google chrome
32bit: wget https://dl.google.com/linux/direct/google-chrome-stable_current_i386.deb sudo dpkg -i go ...
- 关于vue.js中事件处理器的练习
html: <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8 ...
- 配置JDK环境变量,与各步骤的意义
配置JDK环境变量 1,新建变量名:JAVA_HOME,变量值:C:\Program Files\Java\jdk1.7.0 (变量值为jdk安装路径) 2,打开P ...
- zip伪加密文件分析(进阶版)
作者近日偶然获得一misc题,本来以为手到擒来,毕竟这是个大家都讨论烂了的题,详情访问链接http://blog.csdn.net/ETF6996/article/details/51946250.既 ...
- NewQuant的设计(一)——整体的领域设计
NewQuant的设计思路——整体的领域分析 “领域驱动设计(DDD)”是著名软件工程建模专家Eric Evans提出的一个重要概念,是“面向对象分析设计(OOAD)”的深化.当业务逻辑变得复杂,系统 ...
- winfrom自定义控件
c#TabControl控件左边选项卡左边显示,文字横向显示 http://blog.csdn.net/kasama1953/article/details/52133713 WinForm中,给Te ...