BOOL CLandDlg::AdoInit()
{
if(!AfxOleInit())
{
MessageBox("OLE初始化失败");
return FALSE;
}
memset(m_pConnectString,0x0,sizeof(m_pConnectString));
memset(m_pProgPath,0x0,sizeof(m_pProgPath));
GetCurrentDirectory(256,m_pProgPath);                           //获得程序路径
m_pProgPath[strlen(m_pProgPath)]='\\';
strcpy(m_pConnect,"odbc mysqlDRIVER={MySQL ODBC 5.2 ANSI driver};server=localhost;database=test;UID=root;password=326492;option=3306");
strcpy(m_pDBName,"Lander.ibd");
strcat(m_pConnectString,m_pConnect);
strcat(m_pConnectString,m_pProgPath);
strcat(m_pConnectString,m_pDBName);
return TRUE;
}int CLandDlg::OnLogin(CString username,CString pass)
{/*
try 
{ MYSQL m_sqlCon;
mysql_init(&m_sqlCon);  
if(!mysql_real_connect(&m_sqlCon, "localhost","root","326492","test",3306,NULL,0)) 

AfxMessageBox(_T("数据库连接失败!"));  return FALSE; 

return TRUE;  
}  
catch (...) 

return FALSE;  
} */

if (FAILED(m_pRst.CreateInstance(__uuidof(Connection)/*"ADODB.Connection"/*"ADODB.Recordset"*/)))
{
MessageBox("创建 Instance 失败","ERROR");
return FALSE;
} int i = 0;

CString Mysql = "select * from user_t where UserName='"+username+"' and Password='"+pass+"'";
if(FAILED(m_pRst->Open((const _variant_t)Mysql,(const _variant_t)m_pConnectString,adOpenStatic,adLockOptimistic,adCmdText)))
{
m_pRst.Release();
return -1;
}
while(!m_pRst->GetadoEOF())
{
i++;
m_pRst->MoveNext(); }
m_pRst.Release();
return i;
}
连接不上其指导