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();
}