数据库访问与查询

#include <afxwin.h>
#include <afxdb.h>
 
int _tmain(int argc,TCHAR *argv[],TCHAR *envp[])
{
AfxWinInit(GetModuleHandle(NULL),NULL,GetCommandLine(),0);
CDatabase db;
try
{
db.OpenEx("DSN=user1;",CDatabase::noOdbcDialog);
 
}catch(CDBException *pDBEx)
{
pDBEx->ReportError();
 
}catch(CMemoryException *pMemEx)
{
pMemEx->ReportError();
}
CRecordset rs(&db);
 
 
rs.Open(CRecordset::forwardOnly,"select * from user;",CRecordset::readOnly);
while(!rs.IsEOF())
{CString s;
rs.GetFieldValue("name",s);
rs.MoveNext();
AfxMessageBox(s);
}
 
rs.Close();
db.Close();
return 0;
}
posted @ 2013-02-26 12:28  中国男孩  阅读(295)  评论(0编辑  收藏  举报