从ADO获取未排序的记录集
问题描述:
我正在使用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();
}
我该如何使它返回未排序?
答
int ordinalPosition = (int)pSchema->Fields->GetItem("ORDINAL_POSITION")->Value.dblVal;
然后order by ordinalPosition(从索引1开始)。