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 ...
随机推荐
- eclipse导入项目前面有感叹号
1.项目上右击---build path---Config..----Libra----
- wordpress导入模板数据
主题安装完成以后,如果有主题的DEMO数据(xml格式的)的话可以导入,导入后该有的页面与分类文章等等都会有了,这样子会节省很多时间,导入后只需要更改对应的页面与分类就可以了. 导入方法: 1. 在后 ...
- Egit Patch
Git为我们提供了Patch功能,Patch中包含了源码更改的描述,能够应用于其他Eclipse工作空间或者Git仓库.也就是说,可以将当前提交导出至其他分支或者项目中. 举个例子,项目A.B中使 ...
- 获取url的html值
//取当前页面的地址 例如http:127.0.0.1:80/aaa/index.html 返回http:127.0.0.1:80/aaa/function getUrlAddr(){ var str ...
- Oracle cmd 导出数据库或者表定义或者纯数据
实例: expdp zypacs/Sfx371482@zyrisdb schemas=ZYPACS content=metadata_only CONTENT={ALL | DATA_ONLY | M ...
- python3 如何使用ip、爬虫
使用urllib.request.random模块,不说了贴代码 url="*"; iplist=['70.254.226.206:8080'];proxy_support=url ...
- Adobe After Effects工程使用aep格式来存储
写页面的时候发现好几处的按钮都是这种样式,于是把这个按钮的样式单独提取出来放着全局css文件中 .base-btn { display: block; width: 90%; height: 54px ...
- jdb调试命令
常用调试命令: run GeoHashTest #带参数运行 stop at GeoHashTest:22 #断点GeoHashTest文件的22行 stop in GeoHashEncode.Enc ...
- UART
一.协议部分: 协议部分转自:http://www.s8052.com/index.htm 串行通信的传送方向通常有三种: 1.为单工,只允许数据向一个方向传送: 2.半双工,允许数据向两个方向中的任 ...
- Sequential List
Sequential ListSequential list storage structure:#define LIST_INIT_SIZE 20 #define LIST_INCREASE 10t ...