1个回答
展开全部
void XXX::XXXX()
{
CString strSql;
CString strName;
CString strDriver = "MICROSOFT ACCESS DRIVER (*.mdb)";
CString strDsn;
CString strFile = "D:\\Vm.mdb";//数据库路径
strDsn.Format("ODBC;DRIVER=;UID=sa;PWD=;DBQ=%s",strDriver,strFile);
TRY
{
CDatabase m_db;
m_db.Open(NULL,false,false,strDsn);
CString strConnect = m_db.GetConnect();
CRecordset rs(&m_db);
szInstallName = "'" + szInstallName + "'";
strSql = "select * from VMVersions where IRPFile=" + szInstallName;
rs.Open(CRecordset::forwardOnly,strSql,CRecordset::readOnly);
CString szName;
rs.GetFieldValue("ID",strName);
szName = szName +'\n' + strName;
rs.MoveNext();
m_db.Close();
CDatabase m_db1;
m_db1.Open(NULL,false,false,strDsn);
strConnect = m_db1.GetConnect();
CRecordset rs1(&m_db1);
szInstallName = "'" + szInstallName + "'";
strSql = "SELECT * FROM VMCommitVersionNum WHERE VerId = "兆运 + strName;
rs1.Open(CRecordset::forwardOnly,strSql,CRecordset::readOnly);
int nItem, i=0;
CString szTemp = "";
while(!rs1.IsEOF())
{
rs1.GetFieldValue("VersionNum", strName);
nItem = ListCtrl->InsertItem(i, strName);
szTemp = CompareText(szTemp, strName);
rs1.MoveNext();
i++;
}
m_db1.Close();
}
CATCH(CDBException, e)
{
AfxMessageBox("Database Error:" + e->m_strError);
}
END_CATCH;
}
/蠢毕/这是一个简单的使用MFC查询数据库的例子,你可族档梁以参照下这个的用法
{
CString strSql;
CString strName;
CString strDriver = "MICROSOFT ACCESS DRIVER (*.mdb)";
CString strDsn;
CString strFile = "D:\\Vm.mdb";//数据库路径
strDsn.Format("ODBC;DRIVER=;UID=sa;PWD=;DBQ=%s",strDriver,strFile);
TRY
{
CDatabase m_db;
m_db.Open(NULL,false,false,strDsn);
CString strConnect = m_db.GetConnect();
CRecordset rs(&m_db);
szInstallName = "'" + szInstallName + "'";
strSql = "select * from VMVersions where IRPFile=" + szInstallName;
rs.Open(CRecordset::forwardOnly,strSql,CRecordset::readOnly);
CString szName;
rs.GetFieldValue("ID",strName);
szName = szName +'\n' + strName;
rs.MoveNext();
m_db.Close();
CDatabase m_db1;
m_db1.Open(NULL,false,false,strDsn);
strConnect = m_db1.GetConnect();
CRecordset rs1(&m_db1);
szInstallName = "'" + szInstallName + "'";
strSql = "SELECT * FROM VMCommitVersionNum WHERE VerId = "兆运 + strName;
rs1.Open(CRecordset::forwardOnly,strSql,CRecordset::readOnly);
int nItem, i=0;
CString szTemp = "";
while(!rs1.IsEOF())
{
rs1.GetFieldValue("VersionNum", strName);
nItem = ListCtrl->InsertItem(i, strName);
szTemp = CompareText(szTemp, strName);
rs1.MoveNext();
i++;
}
m_db1.Close();
}
CATCH(CDBException, e)
{
AfxMessageBox("Database Error:" + e->m_strError);
}
END_CATCH;
}
/蠢毕/这是一个简单的使用MFC查询数据库的例子,你可族档梁以参照下这个的用法
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询