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 ...
随机推荐
- 网络虚拟化中的 offload 技术:LSO/LRO、GSO/GRO、TSO/UFO、VXLAN
offload 现在,越来越多的网卡设备支持 offload 特性,来提升网络收/发性能.offload 是将本来该操作系统进行的一些数据包处理(如分片.重组等)放到网卡硬件中去做,降低系统 CPU ...
- IOS照片颠倒分析及PHP服务端的处理
前言: 因朋友的PHP小项目, 而去帮忙解决了一个小问题, 现在来总结概括一下. 也不知道大家在使用和开发的过程中有没有遇到类似的场景, IPhone手机上传照片后, 发现图片方向颠倒了, 甚至各种姿 ...
- LeakCanary Android 和 Java 内存泄露检测。
开始使用 在 build.gradle 中加入引用,不同的编译使用不同的引用: dependencies { debugCompile 'com.squareup.leakcanary:leakcan ...
- JDBC中连接MySQL数据库
package qddx.JDBC; import java.sql.*; public class JDBC_Connection { static String driverName = &quo ...
- CodeForces 239A. Triangle
Link: http://codeforces.com/contest/407/problem/A 给定直角三角形的2个直角边a,b.求在直角坐标系中,是否存在对应的直角三角形,使得三个定点都在整点 ...
- java数组引用
public class Arriy { public static void main(String args[]){ int data[]=new int[3]; data[0]=10; data ...
- 备忘DES带向量的加密和解密与DES简单加密与解密
package com.ego.util; import java.security.Key; import java.security.SecureRandom; import java.secur ...
- Search Insert Position
int searchInsert(int* nums, int numsSize, int target) { ; ); ; int mid; while(low<=high){ mid=(lo ...
- Ext.Net 学习随笔 002 默认按钮
在FormPanel中按回车按键,会触发默认按钮的click事件.设置方法为在FormPanel中设置DefaultButton属性,如果没有设置这个属性,默认为最后一个按钮. 1.缺省最后一个按钮为 ...
- iOS面试题汇总
摘要:1. Object-c的类可以多重继承么?可以实现多个接口么?Category是什么?重写一个类的方式用继承好还是分类好?为什么? 答: Object-c的类不可以多重继承;可以实现多个接口,通 ...