主题:求助数据备份问题
bool CDlgBF::BeiFen()
{
LONG lResult;
HKEY hKey;
TCHAR cData[100];
DWORD dDataSize;
lResult = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\ODBC\\ODBC.INI\\yaopin", 0, KEY_QUERY_VALUE, &hKey);
if(lResult == ERROR_SUCCESS)
{
dDataSize = sizeof(cData);
::RegQueryValueEx(hKey, "DBQ", NULL, NULL, (LPBYTE)&cData, &dDataSize);
}else{
MessageBox("没有找到数据库文件", "错误");
return false;
}
MessageBox("请选择路径和文件名称");
CString bf_id = this->ChangShengID();
CFileDialog dlg(false, "mdb", "备份数据" + bf_id, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, "(*.mdb)|*.mdb|");
if(dlg.DoModal() == IDOK)
{
this->BeginWaitCursor();
CString strpath = dlg.GetPathName();
if(! ::CopyFile(cData, strpath, false))
{
MessageBox("文件拷贝失败!", "错误");
this->EndWaitCursor();
return false;
}
CString strSql;
CString strRq = bf_id.Mid(6, 10);
strSql.Format("insert into tabbf(bf_id, rq, bf_path) values('%s',#%s#,'%s')", bf_id, strRq, strpath);
this->m_runSql.RunSQL(strSql);
this->EndWaitCursor();
}
return TRUE;
}
数据备份的主要函数在以上,但CopyFile函数却返回0,不能备份数据.请帮一下我~
{
LONG lResult;
HKEY hKey;
TCHAR cData[100];
DWORD dDataSize;
lResult = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\ODBC\\ODBC.INI\\yaopin", 0, KEY_QUERY_VALUE, &hKey);
if(lResult == ERROR_SUCCESS)
{
dDataSize = sizeof(cData);
::RegQueryValueEx(hKey, "DBQ", NULL, NULL, (LPBYTE)&cData, &dDataSize);
}else{
MessageBox("没有找到数据库文件", "错误");
return false;
}
MessageBox("请选择路径和文件名称");
CString bf_id = this->ChangShengID();
CFileDialog dlg(false, "mdb", "备份数据" + bf_id, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, "(*.mdb)|*.mdb|");
if(dlg.DoModal() == IDOK)
{
this->BeginWaitCursor();
CString strpath = dlg.GetPathName();
if(! ::CopyFile(cData, strpath, false))
{
MessageBox("文件拷贝失败!", "错误");
this->EndWaitCursor();
return false;
}
CString strSql;
CString strRq = bf_id.Mid(6, 10);
strSql.Format("insert into tabbf(bf_id, rq, bf_path) values('%s',#%s#,'%s')", bf_id, strRq, strpath);
this->m_runSql.RunSQL(strSql);
this->EndWaitCursor();
}
return TRUE;
}
数据备份的主要函数在以上,但CopyFile函数却返回0,不能备份数据.请帮一下我~