首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

输出顺序乱掉,该如何处理

2012-12-31 
输出顺序乱掉代码段如下CoInitialize(NULL) _ConnectionPtr m_pConnection(__uuidof(Connection)) _Reco

输出顺序乱掉
代码段如下CoInitialize(NULL);
 _ConnectionPtr m_pConnection(__uuidof(Connection));
 _RecordsetPtr m_pRecordset(__uuidof(Recordset));

 CEdit* pBoxOne;
 pBoxOne=(CEdit*)GetDlgItem(IDC_EDPUT);
 CString str;
 pBoxOne->GetWindowText(str);

 m_pConnection->ConnectionString="Provider=SQLOLEDB.1;Password=123456;Persist Security Info=True;User ID=sa;Initial Catalog=cargo;Data Source=20100701-1040";
 m_pConnection->Open("","","",adConnectUnspecified);

 CString strSql;

 strSql.Format(_T("select * from dbo.master_table_shandonglangjin where mastername='%s'order by id"),str);//按条件查询
 //strSql.Format(_T("select * from dbo.master_table_shandonglangjin order by id"),str);//按条件查询
 
 m_pRecordset=m_pConnection->Execute((_bstr_t)strSql,NULL,adCmdText);

 ((CListBox*)GetDlgItem(IDC_LIOUT))->ResetContent();//清空listbox内的内容
_variant_t var;
CString strID,strCode;

 while(!m_pRecordset->adoEOF)
 {   
 var=m_pRecordset->GetCollect("id");
 if(var.vt!=VT_NULL)
 {
 strID=(LPCSTR)_bstr_t(var);
 }
 var=m_pRecordset->GetCollect("code");
 if(var.vt!=VT_NULL)
 {
    strCode=(LPCSTR)_bstr_t(var);
 }

 ((CListBox*)GetDlgItem(IDC_LIOUT))->AddString(strID + "->"+strCode);
 m_pRecordset->MoveNext();
 }

 m_pRecordset->Close();
 m_pConnection->Close();
 m_pRecordset.Release();
 m_pConnection.Release();
 CoUninitialize();

按照输入条件执行查询的时候,有时候会按照数据库中的顺序正确的数据。有时输出的顺序就不按照数据库中的顺序显示,显示顺序就会乱掉,这是什么造成的,那位大侠帮忙解决一下。
[解决办法]
CBS_SORT

热点排行