Get an unsorted recordset from ADO

落花浮王杯 提交于 2021-01-29 22:07:11

问题


I'm using ADO to get from excel file the table header column names. The problem is the data is returned sorted. I need it in it's original order. This is the code:

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

How can I make it return unsorted?


回答1:


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

Then order by ordinalPosition (starts with index 1).



来源:https://stackoverflow.com/questions/26238439/get-an-unsorted-recordset-from-ado

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!