从ADO获取未排序的记录集

Get an unsorted recordset from ADO

本文关键字:记录 排序 ADO 获取      更新时间:2023-10-16

我正在使用ADO从excel文件中获取表头列名。问题是数据是按排序返回的。我需要它的原始顺序。这是代码:

_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();
}

我怎样才能使它未经排序地返回?

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

然后按ordinalPosition排序(从索引1开始)。