X_DATA_INIT(CAdoTestView)
// NOTE: the ClassWizard will addcommber initialization here
//}}AFX_DATA_INIT
// TODO: add construction code here
m_strConnection = _T("");
m_strSQL = _T("");
m_strTableNcom = _T("");
isDesc = FALSE;
}
最后要将各控件和它们对应的变量关联起来,代码如下:
void CAdoTestView::DoDataExchange(CDataExchange* pDX)
枫叶文学网www.fywxw.com
Visual C++ 6.0 程序设计从入门到精通
·360·
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAdoTestView)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
DDX_Control(pDX, IDC_LISTBOX, m_strListBox);
DDX_Control(pDX, IDC_DATAGRID, m_strDataGrid);
DDX_Text(pDX, IDC_CONNECTION_STRING, m_strConnection);
DDX_Text(pDX, IDC_EXECUTE_STRING, m_strSQL);
}
(2)编写各消息响应函数
前面已经说过,在编写ADO 的程序时,要用try 和catch,否则ADO 调用错误有可能使
程序崩溃,一定要随时记得捕捉_com_error 例外以及其他错误。因此首先编写捕获例外时的
处理函数。为类CAdoTestView 添加public 成员函数void GenerateError(HRESULT hr, PWSTR
pwszDescription),代码如下:
void CAdoTestView::GenerateError(HRESULT hr, PWSTR pwszDescription)
{
CString m_strError;
m_strError.Format("Run-tcom error ’%d (%x)’", hr, hr);
m_strError += "\n\r";
m_strError += pwszDescription;
AfxMessageBox(m_strError);
}
接下来为各个按钮添加响应函数。首先为用来设定数据源的按钮添加响应函数:打开
“ClassWizard”对话框,在“Class ncom”下拉菜单中选择CAdoTestView,在Object IDs 下
拉列表中选