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 ...
随机推荐
- UDP的使用
// // 该类管理所有的UDP发送 #import <Foundation/Foundation.h> #import "AsyncUdpSocket.h" @pr ...
- 【转】构建C1000K的服务器(1) – 基础
原文来自 ideawu 构建C1000K的服务器(1) – 基础 著名的 C10K 问题提出的时候, 正是 2001 年, 到如今 12 年后的 2013 年, C10K 已经不是问题了, 任何一个普 ...
- ASP.NET MVC过滤器中权限过滤器ValidateAntiForgeryToken的用法(Post-Only)
源参考:https://i.cnblogs.com/EditPosts.aspx?opt=1 用途:防止CSRF(跨网站请求伪造). 用法:在View->Form表单中:<%:Html.A ...
- Surprise团队第二周项目总结
Surprise团队第二周项目总结 项目进展 已实现五子棋人人模式部分 人人模式: 基本方式:采取黑棋先行,黑白交替的下棋顺序. 模式:通过鼠标点击相应棋盘中的"交叉点",在lay ...
- Spring任务调度器之Task的使用
Spring Task提供两种方式进行配置,正如大家所想吧,还是一种是annotation(标注),而另外一种就是XML配置了.但其实这里我觉得比较尴尬,因为任务调度这样的需求,通常改动都是比较多的, ...
- Linux中的入口函数main
main()函数,想必大家都不陌生了,从刚开始写程序的时候,大家便开始写main(),我们都知道main是程序的入口.那main作为一个函数,又是谁调用的它,它是怎么被调用的,返回给谁,返回的又是什么 ...
- 关于js中空值比较和传值的问题
昨天写导出功能时,有个条件审核状态,其中一个审核状态的key为0,我也是醉了. 然后我注意到这方面的问题,在网上找了找,我的理解可能有点问题.但是目前也就是这样了,以后在学习吧! 正文: js中各种类 ...
- codeMirror的简单使用,js比较文本差异(标注出增删改)
最近项目需要使用比较文本的差异的功能,在同事的推荐下,使用js脚本来比较,所以codeMirror变成了选择. 当然codeMirror中有其他功能,比较文本差异的只是其中一个功能,本人不在此做介绍, ...
- SpringMVC——返回JSON数据&&文件上传下载
--------------------------------------------返回JSON数据------------------------------------------------ ...
- NTP时间同步服务器设置
一.Window Server设置 [服务器端设置]1) 修改注册表以下键值:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\ ...