问题
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