1.#import "c:\Program Files (x86)\Common Files\System\ADO\msado15.dll" no_namespace rename("EOF","EndOfFile")
2.
listctrl设置为report,基本步骤就是:
(1)插入并设置属性:
m_List.InsertColumn(0,&column);//设置第一列
(2)插入行并设置列
m_List.InsertItem(0,L"");//插入行
//以下为设置这一行的列
m_List.SetItemText(0,0,strID);
m_List.SetItemText(0,1,strTmp);
m_List.SetItemText(0,2,strAge);
3,以下为例子
LVCOLUMN column;
column.mask=LVCF_FMT|LVCF_WIDTH|LVCF_TEXT|LVCF_SUBITEM;
column.fmt=LVCFMT_LEFT; //左对齐
column.cx=70; //宽度
column.iSubItem=0; //第一列
column.pszText=_T("ID"); //标题
m_List.InsertColumn(0,&column);//设置第一列
column.iSubItem=1;
column.pszText=_T("NAME");
m_List.InsertColumn(1,&column);//设置第二列
column.iSubItem=2;
column.pszText=_T("AGE");
m_List.InsertColumn(2,&column);//设置第三列
m_List.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
::CoInitialize(NULL);
//return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
//CoInitialize(NULL);
//try
{
_ConnectionPtr pConn("ADODB.Connection");
pConn->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='D:\\vs2008Test\\testAuto\\testAuto\\data\\db1.mdb';Persist Security Info=False","","",adConnectUnspecified);
_RecordsetPtr pRs("ADODB.Recordset");
pRs->Open("Select * From student",_variant_t(pConn,true),adOpenStatic,adLockOptimistic,adCmdText);
int i = 0;
while(!pRs->EndOfFile)
{
CString strID= (LPCTSTR)_bstr_t(pRs->GetCollect("stuID"));
CString strTmp = (LPCTSTR)_bstr_t(pRs->GetCollect("name"));
CString strAge = (LPCTSTR)_bstr_t(pRs->GetCollect("age"));
m_List.InsertItem(i,L"");//只有加上这一步才能将数据添加进去
m_List.SetItemText(i,0,strID);
m_List.SetItemText(i,1,strTmp);
m_List.SetItemText(i,2,strAge);
pRs->MoveNext(); //catch(_com_error &e)
//cout<<"Password:"<<_bstr_t(pRs->GetCollect("Password"))<
i ++;
}
pRs->Close();
pConn->Close();
}
//{
// //cout<
return 0;