1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
/* rs est le recordset ,
db est un Cdatabase object ,
vectorArray stocke chaque ligne une à une,
resultsList stock tous mes vecteurs , soit les lignes retourné par le SELECT de la base
*/
void Database::SelectQuery()
{
static int currentColumnNumber = 0;
CString tmpString;
vector<CString> vectorArray;
CDBVariant varValue;
// Exécution de la requete
try
{
if (!rs->Open(AFX_DB_USE_DEFAULT_TYPE, this->query))
{
rs->Close();
}
else
{
long numberOfColumns= rs->GetRecordCount();
short numberOfRows = rs->GetODBCFieldCount();
while (! rs->IsBOF() && !rs->IsEOF())
{
vectorArray.clear();
for (int index = 0; index < numberOfRows ; index++)
{
try
{
this->rs->GetFieldValue(index,tmpString);
// this->rs->GetFieldValue(index,varValue);
vectorArray.push_back(tmpString);
}
catch (CDBException* Expt)
{
AfxMessageBox(Expt->m_strError);
Expt->Delete();
}
}
this->resultsList.push_back(vectorArray);
try
{ // champs suivant
rs->MoveNext();
currentColumnNumber++;
}
catch( CDBException* Execp)
{
AfxMessageBox(Execp->m_strError);
Execp->Delete();
break;
}
}
}
}
catch (CDBException* pEx)
{
AfxMessageBox("Open Query Failed , Check the query Type. \n"+pEx->m_strError);
pEx->Delete();
}
} |
Partager