Tiens, voici une extraction de ma librairie ADOLib, qui met le résultat d'un query dans un CListCtrl.
J'espère que cela pourra t'aider. Tu trouveras la librairie et ses sources sur www.adolib.be.tf
J'espère que cela sera lisibile.
Bàt,
Pierre
/* Display the result of the query into a ListView
* Example: *
<CODE>//Define the ConnectSTring
Cstring sProvider("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\\\\dev\\\\vc\\\\ADOExemple.mdb;Persist Security Info=False");
ADOConnect myConn;
// Get connected to the DB
if (!myConn.Connect(sProvider)) {
cout \<\< myConn.GetError() \<\< endl; //Display the error
exit (0);
} else {
ADOLibDC myDC;
if (!myDC.Open(myConn.ADOConn, "select * from emp")){
cout \<\< myDC.GetError() \<\< endl; // Display the error
} else {
myDC.FetchInListCtrl(&m_ListView);
myDC.Close();
}
//Disconnect from the DB
myConn.Disconnect();
}
Parameters
pmyListCtrl : Pointer to the ListCtrl object that will receive
the data */
int ADOLibDC::FetchInListCtrl(CListCtrl *pmyListCtrl // Pointer to the ListCtrl object that will receive the data
)
{
int iColCount = GetColCount();
pmyListCtrl->DeleteAllItems();
int nColumnCount = pmyListCtrl->GetHeaderCtrl()->GetItemCount();
// Delete all of the columns.
for (int i=0;i < nColumnCount;i++)
{
pmyListCtrl->DeleteColumn(0);
}
if (!eof()){
for (int i=0; i < iColCount; i++) {
pmyListCtrl->InsertColumn(i, GetFieldName(i), LVCFMT_LEFT, 100);
}
int iRec=0;
while (Fetch())
{
CString txt;
GetFieldVal(0, txt);
pmyListCtrl->InsertItem(iRec, (LPCSTR) (_bstr_t)txt);
for (int iCol = 1;iCol < iColCount; iCol++)
{
if (GetFieldVal(iCol, txt)) {
pmyListCtrl->SetItemText(iRec, iCol, (LPCSTR) (_bstr_t)txt);
}
}
iRec++;
}
}
//Close();
return true;
}
</code>