利用ListControl控件浏览数据

 
m_datalist.ModifyStyle(0L,LVS_REPORT);
	m_datalist.ModifyStyle(0L,LVS_SINGLESEL);
	m_datalist.ModifyStyle(0L,LVS_SHOWSELALWAYS);
	m_datalist.ModifyStyle(0L,LVS_NOSORTHEADER);
	m_datalist.SetExtendedStyle(LVS_EX_GRIDLINES);
	m_datalist.InsertColumn(0,"学号");
	m_datalist.InsertColumn(1,"姓名");
	m_datalist.InsertColumn(2,"性别");
	m_datalist.SetColumnWidth(0,100);
	m_datalist.SetColumnWidth(1,100);
	m_datalist.SetColumnWidth(2,100);
	::CoInitialize(NULL);
	m_pConnection=NULL;
	m_pConnection.CreateInstance(__uuidof(Connection));
	m_pConnection->ConnectionString="DSN=szdns;UID="";PWD="" ";
	m_pConnection->Open("","","",adConnectUnspecified);
	_bstr_t bstrSQL="select * from sc";
   	m_pRecordset=m_pConnection->Execute(bstrSQL,NULL,adCmdText);
	int i=0;
	while(!m_pRecordset->adoEOF)
	{
	xm=(char*)(_bstr_t)m_pRecordset->GetCollect("sno");
	xb=(char*)(_bstr_t)m_pRecordset->GetCollect("sname");
	csrq=(char*)(_bstr_t)m_pRecordset->GetCollect("sex");
	m_datalist.InsertItem(i,"");
	m_datalist.SetItemText(i,0,xm);
	m_datalist.SetItemText(i,1,xb);
	m_datalist.SetItemText(i,2,csrq);
	i+=1;
	m_pRecordset->MoveNext();
	}
	m_pRecordset->Close();
	m_pConnection->Close();
	m_pRecordset=NULL;
	m_pConnection=NULL;
	::CoUninitialize();

你可能感兴趣的:(利用ListControl控件浏览数据)