// TODO: Add extra initialization here
m_listLinkInfo.SetExtendedStyle(LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT);
int i=0;
m_listLinkInfo.InsertColumn(i++, "ID", LVCFMT_LEFT, 90);
m_listLinkInfo.InsertColumn(i++, "Name", LVCFMT_LEFT, 90);
m_listLinkInfo.InsertColumn(i++, "Age", LVCFMT_LEFT, 90);
///
m_Recordset = m_Ado.GetRecordset();
//调用成员函数定位到第一条记录
m_Recordset.MoveFirst();
/
void CMyADOControlDlg::OnBtnShow()
{
m_listLinkInfo.DeleteAllItems();
int i=0, j=0;
CString strTmp;
COleVariant m_OleVariant;
//由记录对象调用成员函数得到当前记录的字段集,然后赋给字段集对象
m_Fields = m_Recordset.GetFields();
m_Recordset.MoveFirst();
//while语句实现学生的查找,循环条件是还有到达记录集的末尾
while(!m_Recordset.GetEof()) //&&!m_Found)
{
//获得第1个字段对象(学生ID)
m_Field = m_Fields.GetItem(COleVariant(long(0)));
//获得该字段值
m_OleVariant = m_Field.GetValue();
//strTmp= m_OleVariant.bstrVal;
strTmp.Format("%ld",m_OleVariant.uintVal);
m_listLinkInfo.InsertItem(i, strTmp);
//获得第2个字段对象(学生Name)
m_Field = m_Fields.GetItem(COleVariant(long(1)));
//获得该字段值
m_OleVariant = m_Field.GetValue();
strTmp = m_OleVariant.bstrVal;
m_listLinkInfo.SetItemText(i, ++j, strTmp);
//获得第3个字段对象(学生Age)
m_Field = m_Fields.GetItem(COleVariant(long(2)));
//获得该字段值
m_OleVariant = m_Field.GetValue();
strTmp = m_OleVariant.bstrVal;
m_listLinkInfo.SetItemText(i, ++j, strTmp);
i++;
j=0;
//查找下一条记录
m_Recordset.MoveNext();
}
//*
//若到达记录集的末尾,则重新定位到第一条记录
if(m_Recordset.GetEof())
m_Recordset.MoveFirst();
//*/
}