BOOL CAddDateToListDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
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.InsertColumn(3,"工作单位");
m_datalist.InsertColumn(4,"移动电话");
m_datalist.InsertColumn(4,"固定电话");
m_datalist.SetColumnWidth(0,100);
m_datalist.SetColumnWidth(1,50);
m_datalist.SetColumnWidth(2,100);
m_datalist.SetColumnWidth(3,100);
m_datalist.SetColumnWidth(4,100);
m_datalist.SetColumnWidth(5,100);
::CoInitialize(NULL);
m_pConnection=NULL;
m_pConnection.CreateInstance(__uuidof(Connection));
m_pConnection->ConnectionString="uid=;pwd=;DRIVER={Microsoft Access Driver (*.mdb)};DBQ=mrdb.mdb;";
m_pConnection->Open(L"",L"",L"",adCmdUnspecified);
_bstr_t bstrSQL="select * from info";
m_pRecordset=m_pConnection->Execute(bstrSQL,NULL,adCmdText);
int i=0;
while(!m_pRecordset->adoEOF)
{
xm=(char*)(_bstr_t)m_pRecordset->GetCollect("xm");
xb=(char*)(_bstr_t)m_pRecordset->GetCollect("xb");
csrq=(char*)(_bstr_t)m_pRecordset->GetCollect("csrq");
gzdw=(char*)(_bstr_t)m_pRecordset->GetCollect("gzdw");
yddh=(char*)(_bstr_t)m_pRecordset->GetCollect("yddh");
gddh=(char*)(_bstr_t)m_pRecordset->GetCollect("gddh");
m_datalist.InsertItem(i,"");
m_datalist.SetItemText(i,0,xm);
m_datalist.SetItemText(i,1,xb);
m_datalist.SetItemText(i,2,csrq);
m_datalist.SetItemText(i,3,gzdw);
m_datalist.SetItemText(i,4,yddh);
m_datalist.SetItemText(i,5,gddh);
i+=1;
m_pRecordset->MoveNext();
}
m_pRecordset->Close();
m_pConnection->Close();
m_pRecordset=NULL;
m_pConnection=NULL;
::CoUninitialize();
return TRUE; // return TRUE unless you set the focus to a control
}
1.添加listctrl控件并关联CListCtrl变量m_datalist
2.为CxxDlg类添加成员
_ConnectionPtr m_pConnection;
_RecordsetPtr m_pRecordset;
3.在StdAfx.h添加
#import "c:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF" ,"adoEOF")
(在使用ADO技术时,需要导入一个ADO动态链接库msado15.dll,该动态库位于系统盘下的“Program Files\Common Files\System\ado\”目录下。)
example60
http://download.csdn.net/detail/luck_good/3787963