本文的代码没有按照教材上的来
在initDlg()中
将listctrl风格改为整行选取
m_list.SetExtendedStyle(m_list.GetExtendedStyle()|LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES );
按键提取数据
连接对象 记录集对象
void CMy0714BDlg::OnBnClickedButton1()
{
// TODO: Add your control notification handler code here
CoInitialize(NULL); //初始化COM环境
_ConnectionPtr pMyConnect(__uuidof(Connection));//定义连接对象并实例化对象
<span style="white-space:pre"> //_ConnectionPtr智能指针</span>
_RecordsetPtr pRst(__uuidof(Recordset)); //定义记录集对象并实例化对象
try
{
//步骤2:创建数据源连接
/*打开数据库“SQLServer”,这里需要根据自己PC的数据库的情况 */
pMyConnect->Open("Provider=SQLOLEDB; Server=.;Database=B; uid=sa; pwd=123;","","",adModeUnknown);
}
catch(_com_error &e)
{
//cout<<"Initiate failed!"<<endl;
CString str;
str="初始化连接对象失败!\r\n";
str+=(LPCSTR)(e.Description()); //_bstr_t 转CString
str+="\r\n";
str+=(LPCSTR)(e.HelpFile());
::AfxMessageBox(str);
//cout<<e.Description()<<endl;
//cout<<e.HelpFile()<<e