📄 c_cresultset.cpp
字号:
// c_CResultSet.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "c_CResultSet.h"
#include "afxdb.h"
#include "MyRecordSet.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// The one and only application object
CWinApp theApp;
using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
// initialize MFC and print and error on failure
AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0);
//---------------ADD MY OWN CODE HERE!---------------------------//
//---------------用CDatabase对数据库进行连接---------------------//
/*
CMyRecordSet rs;
if( rs.IsOpen() )
rs.Close();
rs.Open(AFX_DB_USE_DEFAULT_TYPE,(LPCTSTR)"select * from PersonInfo");
cout<<"输出数据:"<<endl;
while( !rs.IsEOF() )
{
cout<<"\n名字:"<<(LPCTSTR)rs.m_Name;
cout<<"\n年龄:"<<rs.m_Age;
cout<<"\n性别:"<<(LPCTSTR)rs.m_Sex;
rs.MoveNext();
}
if( rs.IsOpen() )
rs.Close();
*/
cout<<"\n\n<--------------------------------------------------->\n\n";
//---------------------CMyRecordSet 使用 CDatabase与数据库的连接-----------------------//
try{
CDatabase cd;
//cd.Open(_T("MyDB_connect"),FALSE,FALSE,_T("ODBC;PWD=1234"),TRUE); //不调用此函数,会显示一个连接数据源的对话框
CMyRecordSet o_rs(&cd);
o_rs.Open(AFX_DB_USE_DEFAULT_TYPE,(LPCTSTR)"select * from PersonInfo");
//--------列出数据---------//
while( !o_rs.IsEOF() )
{
cout<<"\n名字:"<<(LPCTSTR)o_rs.m_Name;
cout<<"\n年龄:"<<o_rs.m_Age;
cout<<"\n性别:"<<(LPCTSTR)o_rs.m_Sex;
o_rs.MoveNext();
}
o_rs.MoveFirst();
//-----添加数据-------//
o_rs.AddNew();
o_rs.m_Name = "Jhon";
o_rs.m_Age = 23;
o_rs.m_Sex = "male";
if( o_rs.CanUpdate() )
{
o_rs.Update();
}
o_rs.Requery();
//-----------删除数据-------------//
o_rs.Move(3);
while( !o_rs.IsEOF() )
{
o_rs.Delete();
o_rs.MoveNext();
}
if( cd.IsOpen() )
cd.Close();
if( o_rs.IsOpen() )
o_rs.Close();
}
catch(CDBException* e)
{
e->ReportError();
}
catch(...)
{
cout<<"\tWarnning: Unexpected errors!"<<endl;
}
cout<<"\n\n";
return nRetCode;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -