2014-10-07 62 views
0

我正在使用ADO從excel文件中獲取表標題列名稱。問題是數據被返回排序。我需要它的原始順序。這是代碼:從ADO獲取未排序的記錄集

_RecordsetPtr pSchema->m_pCon->OpenSchema(adSchemaColumns); 
// pSchema->Sort = ""; // Does not help 
// pSchema->Sort = "ORDINAL_POSITION"; // Crashes 
while (!pSchema->GetadoEOF()) 
{ 
    string sheetName = (char*)(_bstr_t)pSchema->Fields->GetItem("TABLE_NAME")->Value.bstrVal; 
    if (sheetName == "MySheet") 
     string column = (char*)(_bstr_t)pSchema->Fields->GetItem("COLUMN_NAME")->Value.bstrVal; 
    pSchema->MoveNext(); 
} 

我該如何使它返回未排序?

回答

0
int ordinalPosition = (int)pSchema->Fields->GetItem("ORDINAL_POSITION")->Value.dblVal; 

然後order by ordinalPosition(從索引1開始)。