4,018
社区成员




AfxOleInit();
AfxEnableControlContainer();
::CoInitialize(NULL); //初始化COM组件
_ConnectionPtr m_pConnection;
m_pConnection.CreateInstance(__uuidof(Connection));
_RecordsetPtr pRst(__uuidof(Recordset));
pRst.CreateInstance(__uuidof(Recordset));
_CommandPtr pCmd(__uuidof(Command)); //实例化一个Command对象pCmd
// m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=FilterDateBase.mdb","","",adModeUnknown);
try
{
m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=FilterDateBase.mdb;Persist Security Info=False;Jet OLEDB:Database Password=TENNI","","",adModeUnknown);
}
catch(_com_error e)
{
AfxMessageBox("数据库连接失败,请检查数据库FilterDateBase.mdb!");
return;
}
UpdateData();
void CResult::On_Save()
{
CFileDialog fileDlg(FALSE,"txt","testfile");
fileDlg.m_ofn.lpstrTitle="保存为";
fileDlg.m_ofn.hwndOwner = AfxGetMainWnd()->GetSafeHwnd();//另存为时,防止覆盖
fileDlg.m_ofn.lpstrFilter="文本文档(*.txt)\0*.txt\0Excel表格(*.xls)\0*.xls\0所有文件(*.*)\0*.*\0\0";
fileDlg.m_ofn.lpstrDefExt="txt";
if(IDOK==fileDlg.DoModal())
{
UpdateData();//取文本框字符
CFile file(fileDlg.GetFileName(),CFile::modeCreate | CFile::modeWrite);
file.Write("欢迎您使用 \r\n",strlen("欢迎您使用 \r\n"));
file.Close();
UpdateData(FALSE);
MessageBox("保存文件成功", "保存成功", MB_ICONEXCLAMATION | MB_OK);
}
else {
MessageBox("保存文件失败", "保存失败", MB_ICONSTOP | MB_OK);
}
}
try
{
//你的ADO代码
}
catch (_com_error& e)
{
AfxMessageBox(e.Description());
}