⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 danview.cpp

📁 数据库操作 连接odbc的前期操作 或者是对主机的处理工作
💻 CPP
字号:
// danView.cpp : implementation of the CDanView class
//

#include "stdafx.h"
#include "dan.h"

#include "danSet.h"
#include "danDoc.h"
#include "danView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//#include "Afxwin.h"
/////////////////////////////////////////////////////////////////////////////
// CDanView

IMPLEMENT_DYNCREATE(CDanView, CRecordView)

BEGIN_MESSAGE_MAP(CDanView, CRecordView)
	//{{AFX_MSG_MAP(CDanView)
	ON_COMMAND(ID_linodbc, Onlinodbc)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CRecordView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CRecordView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CRecordView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDanView construction/destruction

CDanView::CDanView()
	: CRecordView(CDanView::IDD)
{
	//{{AFX_DATA_INIT(CDanView)
	m_pSet = NULL;
	//}}AFX_DATA_INIT
	// TODO: add construction code here

}

CDanView::~CDanView()
{
}

void CDanView::DoDataExchange(CDataExchange* pDX)
{
	CRecordView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDanView)
	//}}AFX_DATA_MAP
}

BOOL CDanView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CRecordView::PreCreateWindow(cs);
}

void CDanView::OnInitialUpdate()
{
	m_pSet = &GetDocument()->m_danSet;
	CRecordView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();

}

/////////////////////////////////////////////////////////////////////////////
// CDanView printing

BOOL CDanView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CDanView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CDanView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CDanView diagnostics

#ifdef _DEBUG
void CDanView::AssertValid() const
{
	CRecordView::AssertValid();
}

void CDanView::Dump(CDumpContext& dc) const
{
	CRecordView::Dump(dc);
}

CDanDoc* CDanView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDanDoc)));
	return (CDanDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CDanView database support
CRecordset* CDanView::OnGetRecordset()
{
	return m_pSet;
}


/////////////////////////////////////////////////////////////////////////////
// CDanView message handlers

void CDanView::Onlinodbc() 
{
   // ClistBox m_list;
	CString strDriver = "MICROSOFT ACCESS DRIVER (*.mdb)";   ///对strDsn的定义 
	CString strDsn;
	CString strFile = "newhd.mdb";
	strDsn.Format("ODBC;DRIVER={%s};DBQ=%s",strDriver,strFile);

	CDatabase m_pdatebase;
	m_pdatebase.Open(_T("New"),false,false,_T(strDsn));//连接数据源
	CRecordset Bookinfo(&m_pdatebase);
	Bookinfo.Open(CRecordset::snapshot,_T("Select * from 计表01"),CRecordset::readOnly);  //从表里取出数据 为静态变量 
    ////////////////////////////////////////////////////////////遍历记录集 
	                                          
	///////////////////m_pset是记录集指针 ,m_list列表框控件的变量 
 
	if(!m_pSet->IsOpen ())     ////	若记录集未打开,执行open()打开
        m_pSet->Open();
	    m_pSet->MoveFirst ();     ////记录集移到第一条记录 
	while(!m_pSet->IsEOF ())    // 未移到最后一条都进行循环 
	{
//	m_list.AddString(m_pSet->m_column1 );/////////调用ClistBox类中的AddString函数
    //	m_pSet->MoveNext ();
        //char id[2] ;
	//	itoa(m_pSet->m_ID,id,strlen(id)) ;
	//	MessageBox(id) ;
		MessageBox(m_pSet->m_column2) ;
		m_pSet->MoveNext () ;
		
	}
	/*
	//////////////////////////////////////////参数化记录集 
	CString name;         //// 声明参变量
	CString age;
	CString num;
	name = _T("");          ////在构造函数中初始化参变量 
	age = _T("");
	num = _T("");
	///////////////////
	pFX->SetFieldType(CFieldExchange::param );
//	RFX_Long(pFX, _T("[编号]"), m_column1);
	RFX_Text(pFX, _T("[姓名]"), name 1);
	RFX_Long(pFX, _T("[年龄]"), age 1);
	RFX_Long(pFX, _T("[成绩]"), num 1);
	*/
} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -