void CStuDlg::List(CString sql) //将SQL语句查询的结果显示在列表框中
{
m_MyList.DeleteAllItems();
int i=0;
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*) theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
if(!m_pRecordset->adoEOF) //如果记录不为空
{
while(!m_pRecordset->adoEOF)
{m_MyList.InsertItem(i,(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Sno"));
m_MyList.SetItemText(i,1,(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Sname"));
m_MyList.SetItemText(i,2,(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Ssex"));
m_MyList.SetItemText(i,3,(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Sage"));
m_MyList.SetItemText(i,4,(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Sdept"));
i++;
m_pRecordset->MoveNext();
}
}
m_pRecordset->Close();
}
原文地址:http://dev.csdn.net/article/70/70671.shtm
数据库查询以及插入LIST列表函数
最新推荐文章于 2023-08-06 11:27:44 发布