CDatabase database;
CString sDriver;
CString sItem1,sItem2;
CString sDsn;
CString sFile="";//filename
CString sSql;
CFileDialog dlg( TRUE, //true为打开,false为创建
"xls",
"FileList",
OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
"Excel 文件(*.xls)|*.xls||"//此处只取xls格式
);
dlg.m_ofn.lpstrTitle = "导入数据";
if (dlg.DoModal() != IDOK)
return;
//获得文件路径名
sFile = dlg.GetPathName();
//判断文件是否已经存在,存在则打开文件
DWORD dwRe = GetFileAttributes(sFile);
if ( dwRe != (DWORD)-1 )
{
}
else return;
//check driver
//sDriver=GetExcelDriver();
sDriver = "MICROSOFT EXCEL DRIVER (*.XLS)";
sDsn.Format("ODBC;DRIVER={%s};DSN='''';DBQ=%s",sDriver,sFile);
TRY
{
//open db
database.Open(NULL,false,false,sDsn);
CRec