void CODBCdatabaseDlg::OnButconnect()
{
// TODO: 在此添加控件通知处理程序代码
SQLRETURN ret;
UpdateData(true);
m_list.ResetContent();
OnInitODBCConn(m_edit);
SQLCHAR no[100] = { 0 }, age[1000] = { 0 };
SQLCHAR name[200] = { 0 }, sex[20] = { 0 };
SQLINTEGER length;
//******************分配执行语句句柄*********************
ret = SQLAllocHandle(SQL_HANDLE_STMT, m_sqlHdbc, &m_sqlHstmt);
//****************************查******************
ret = SQLExecDirect(m_sqlHstmt, (SQLTCHAR*)L"select '编号','姓名' from student;", SQL_NTS);
if (!SQL_SUCCEEDED(ret))
{
AfxMessageBox(L"执行失败");
return;
}
//查的结果必须要使用sqlbindcol函数将结果与用户缓冲区绑定**************
SQLBindCol(m_sqlHstmt, 1, SQL_C_TCHAR, (void*)no, sizeof(no), (SQLLEN*)&length);
SQLBindCol(m_sqlHstmt, 2, SQL_C_TCHAR, (void*)name, sizeof(name), (SQLLEN*)&length);
CString str1,str2;
str1 = (char*)(_bstr_t)no;
str2 = (char*)(_bstr_t)name;
while (SQL_NO_DATA != SQLFetch(m_sqlHstmt))
{
m_list.AddString(str1);
m_list.AddString(str2);
}
ExitConnect();
}