Przesłanianie dynamiczne akcesor
Kiedy używać dynamicznych akcesor takich jak CDynamicAccessor, polecenie Otwórz metoda tworzy akcesor operacji dla automatycznie na podstawie informacji kolumny otwartych wierszy.Można zastąpić dynamiczne akcesor do sterowania dokładnie tak, jak są powiązane kolumny.
Aby zastąpić akcesor dynamiczne, przekazać false jako ostatni parametr CCommand::Open metody.Zapobiega to Otwórz z automatycznego tworzenia akcesor operacji.Następnie można wywołać GetColumnInfo i AddBindEntry dla każdej kolumny, które chcesz powiązać.Poniższy kod pokazuje, jak to zrobić:
USES_CONVERSION;
double dblProductID;
CCommand<CDynamicAccessor> product;
// Open the table, passing false to prevent automatic binding
product.Open(session, _T("Select * FROM Products"), NULL, NULL, DBGUID_DEFAULT, false);
ULONG nColumns;
DBCOLUMNINFO* pColumnInfo;
// Get the column information from the opened rowset.
product.GetColumnInfo(&nColumns, &pColumnInfo);
// Bind the product ID as a double.
pColumnInfo[0].wType = DBTYPE_R8;
pColumnInfo[0].ulColumnSize = 8;
product.AddBindEntry(pColumnInfo[0]);
// Bind the product name as it is.
product.AddBindEntry(pColumnInfo[1]);
// Bind the reorder level as a string.
pColumnInfo[8].wType = DBTYPE_STR;
pColumnInfo[8].ulColumnSize = 10;
product.AddBindEntry(pColumnInfo[8]);
// You have finished specifying the bindings. Go ahead and bind.
product.Bind();
// Free the memory for the column information that was retrieved in
// previous call to GetColumnInfo.
CoTaskMemFree(pColumnInfo);
char* pszProductName;
char* pszReorderLevel;
bool bRC;
// Loop through the records tracing out the information.
while (product.MoveNext() == S_OK)
{
bRC = product.GetValue(1, &dblProductID);
pszProductName = (char*)product.GetValue(2);
pszReorderLevel = (char*)product.GetValue(9);
ATLTRACE(_T("Override = %lf \"%s\" \"%s\"\n"), dblProductID,
A2T(pszProductName), A2T(pszReorderLevel));
}