打印本文 打印本文 关闭窗口 关闭窗口
VC下的ADO编程入门(2-4)
作者:武汉SEO闵涛  文章来源:敏韬网  点击数2451  更新时间:2009/4/23 10:49:55  文章录入:mintao  责任编辑:mintao
_t bstrSource(e.Source());

                   _bstr_t bstrDescription(e.Description());

                   TRACE("Exception throw for classes generated by #import");

                   TRACE("\tCode=%08lx\n", e.Error);

                   TRACE("\tCode meaning = %s\n", e.ErrorMessage);

                   TRACE("\tSource = %s\n", (LPCTSTR)bstrSource);

                   TRACE("\tDescription = %s\n", (LPCTSTR)bstrDescription);

         }

         catch(...)

         {

                   TRACE("Unhandled Exception");

         }

n          添加对话框的WM_Destroy消息响应函数

void CZjyDlg::OnDestroy()

{

         CDialog::OnDestroy();

        

         // TODO: Add your message handler code here

         if(m_IsConnectionOpen)

         {

                    m_IsConnectionOpen=false;

                    m_pConnection->Close();

                    

                    m_pConnection=NULL;

                    m_pRecordset=NULL;

         }

}

n          最后添加按钮的消息响应函数如下

void CZjyDlg::OnButton1()

{

         // TODO: Add your control notification handler code here

         VARIANT_BOOL valEof;

        

         HRESULT hr;

        

         CString strColName;BSTR bstrColName;

 

         CString strValue;VARIANT varValue;

 

         long  ColCount,i; int RowCount=0;

         Fields * fields=NULL;Field * field=NULL;

 

         VARIANT varCounter;

         varCounter.vt=VT_I4;

         varCounter.lVal=0;

 

         try

         {

                   m_list.DeleteAllItems();

                   while(m_list.DeleteColumn(0));

 

                   hr=m_pRecordset->get_Fields(&fields);

                   if(SUCCEEDED(hr)) hr=fields->get_Count(&ColCount);

                   for(i=0;i<ColCount;i++)

                   {       

                            hr=fields->Item[i]->get_Name(&bstrColName);

                            strColName=bstrColName;

                            int nWidth=m_list.GetStringWidth(strColName)+15;

                            m_list.InsertColumn(i,strColName,LVCFMT_LEFT,nWidth);

                   }

                   if(SUCCEEDED(hr)) fields->Release();

 

                   m_pRecordset->get_adoEOF(&valEof);

                   while(true)

 

上一页  [1] [2] [3] [4]  下一页

打印本文 打印本文 关闭窗口 关闭窗口