【VC开源代码栏目提醒】:网学会员VC开源代码为您提供Ex11_2View.cpp参考,解决您在Ex11_2View.cpp学习中工作中的难题,参考学习。
// Ex11_2View.cpp : implementation of the CEx11_2View class
//
#include "stdafx.h"
#include "Ex11_2.h"
#include "Ex11_2Doc.h"
#include "Ex11_2View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CEx11_2View
IMPLEMENT_DYNCREATE(CEx11_2View, CFormView)
BEGIN_MESSAGE_MAP(CEx11_2View, CFormView)
//{{AFX_MSG_MAP(CEx11_2View)
ON_COMMAND(ID_RECORD_FIRST, OnRecordFirst)
ON_COMMAND(ID_RECORD_NEXT, OnRecordNext)
ON_COMMAND(ID_RECORD_PREV, OnRecordPrev)
ON_COMMAND(ID_RECORD_LAST, OnRecordLast)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CEx11_2View construction/destruction
CEx11_2View::CEx11_2View()
: CFormView(CEx11_2View::IDD)
{
//{{AFX_DATA_INIT(CEx11_2View)
m_strStuClass = _T("");
m_strStuCollege = _T("");
m_strStuID = _T("");
m_strStuName = _T("");
m_strStuNativePlace = _T("");
//}}AFX_DATA_INIT
// TODO: add construction code here
}
CEx11_2View::~CEx11_2View()
{
}
void CEx11_2View::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CEx11_2View)
DDX_Text(pDX, IDC_STUCLASS, m_strStuClass);
DDX_Text(pDX, IDC_STUCOLLEGE, m_strStuCollege);
DDX_Text(pDX, IDC_STUID, m_strStuID);
DDX_Text(pDX, IDC_STUNAME, m_strStuName);
DDX_Text(pDX, IDC_STUNATIVEPLACE, m_strStuNativePlace);
//}}AFX_DATA_MAP
}
BOOL CEx11_2View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CFormView::PreCreateWindow(cs);
}
void CEx11_2View::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
ShowTable();//显示数据库数据表
}
/////////////////////////////////////////////////////////////////////////////
// CEx11_2View printing
BOOL CEx11_2View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CEx11_2View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CEx11_2View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
void CEx11_2View::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
// TODO: add customized printing code here
}
/////////////////////////////////////////////////////////////////////////////
// CEx11_2View diagnostics
#ifdef _DEBUG
void CEx11_2View::AssertValid() const
{
CFormView::AssertValid();
}
void CEx11_2View::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CEx11_2Doc* CEx11_2View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CEx11_2Doc)));
return (CEx11_2Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CEx11_2View message handlers
void CEx11_2View::ShowTable()//显示表中的数据
{
_variant_t vstrSQL;
vstrSQL="SELECT * FROM Studenttab " ;//"SELECT *FROM Studenttab"
try
{
HRESULT hTRes;
hTRes =theApp.m_pADOSet.CreateInstance(_T("ADODB.Recordset"));
if (SUCCEEDED(hTRes))
{
hTRes = theApp.m_pADOSet->Open(vstrSQL,
_variant_t((IDispatch *)(((CEx11_2App*)AfxGetApp())->m_pADOConn),
true),adOpenDynamic,adLockPessi
mistic,adCmdText);
if(SUCCEEDED(hTRes))
{
TRACE(_T("连接成功!\n"));
if(theApp.m_pADOSet->BOF)
{
return;
}
if(theApp.m_pADOSet->MoveFirst()==S_OK)
{
m_strStuID=theApp.VariantToCString(theApp.m_pADOSet->GetCollect("StuID"));
m_strStuName=theApp.VariantToCString(theApp.m_pADOSet->GetCollect("StuName"));
m_strStuNativePlace=theApp.VariantToCString(theApp.m_pADOSet->GetCollect("StuNativePlace"));
m_strStuClass=theApp.VariantToCString(theApp.m_pADOSet->GetCollect("StuClass"));
m_strStuCollege=theApp.VariantToCString(theApp