1. First of all, these methods are also the data I collected, and then for the use of the program, the deficiencies, but also please the master guidance.
2. There are a lot of examples of importing and exporting with SQL statements, which are not repeated here.
Method 1: Call the COM component, export Access data to Excel, directly invoke Access's export function, which is super fast
using Access;
Access.ApplicationClass oAccess = new Access.ApplicationClass();
oAccess.Visible = false;
try
{
//ACCESS9:
oAccess.OpenCurrentDatabase("d:wcf.mdb",false,"");
//导出到excel
oAccess.DoCmd.TransferSpreadsheet(Access.AcDataTransferType.acExport,Access.AcSpreadSheetType.acSpreadsheetTypeExcel9,"工作表名","d:wcf.xls",true,null,null);
//导入txt
// oAccess.DoCmd.TransferText(Access.AcTextTransferType.acExportDelim,"","Enterprise","d:wcf.txt",true,"",0);
oAccess.CloseCurrentDatabase();
oAccess.DoCmd.Quit(Access.AcQuitOption.acQuitSaveNone);
System.Runtime.InteropServices.Marshal.ReleaseComObject (oAccess);
oAccess = null;
MessageBox.Show("导入成功");
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
GC.Collect();
}