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

📄 adotestdlg.cpp

📁 WINCE下数据库的一些操作
💻 CPP
字号:
// AdoTestDlg.cpp : implementation file
//

#include "stdafx.h"
#include "AdoTest.h"
#include "AdoTestDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAdoTestDlg dialog

CAdoTestDlg::CAdoTestDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CAdoTestDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CAdoTestDlg)
	m_strFld1 = _T("");
	m_strFld2 = _T("");
	m_strDB = _T("testdb");
	m_strTable = _T("testtbl");
	m_strSql = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CAdoTestDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAdoTestDlg)
	DDX_Text(pDX, IDC_EDFLD1, m_strFld1);
	DDX_Text(pDX, IDC_EDFLD2, m_strFld2);
	DDX_Text(pDX, IDC_EDDB, m_strDB);
	DDX_Text(pDX, IDC_EDTBL, m_strTable);
	DDX_Text(pDX, IDC_EDSQL, m_strSql);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAdoTestDlg, CDialog)
	//{{AFX_MSG_MAP(CAdoTestDlg)
	ON_BN_CLICKED(IDC_BTNCREATEDB, OnBtncreatedb)
	ON_BN_CLICKED(IDC_BTNOPENDB, OnBtnopendb)
	ON_BN_CLICKED(IDC_BTNCLOSEDB, OnBtnclosedb)
	ON_BN_CLICKED(IDC_BTNADDITEM, OnBtnadditem)
	ON_BN_CLICKED(IDC_BTNPREV, OnBtnprev)
	ON_BN_CLICKED(IDC_BTNNEXT, OnBtnnext)
	ON_BN_CLICKED(IDC_BTNCREATETBL, OnBtncreatetbl)
	ON_BN_CLICKED(IDC_BTNOPENTBL, OnBtnopentbl)
	ON_BN_CLICKED(IDC_BTNCLOSETBL, OnBtnclosetbl)
	ON_BN_CLICKED(IDC_BTNEXE, OnBtnexe)
	ON_BN_CLICKED(IDC_BTNEXIT, OnBtnexit)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAdoTestDlg message handlers

BOOL CAdoTestDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	CenterWindow(GetDesktopWindow());	// center to the hpc screen

	// TODO: Add extra initialization here
//	result = DesktopToDevice("c:\mydbs\nwind.mdb", _
//	"!Employees..Products.ID.Name.Quantity..", False, True, "")
//	If result <> 0 Then MsgBox "An error occurred transferring the data"
/*
	if(!m_db.CreateDatabase(L"\\testdb.cdb"))
		MessageBox(L"Create Database Error");
*/

/*
	if(!m_db.Query(L"INSERT INTO TESTTBL(itemid,amount) VALUES(2,2)"))
		MessageBox(L"Query Error");
*/
/*
	if(!m_db.Query(L"SELECT * FROM TESTTBL",&pRS))
		MessageBox(L"Quer Error");
	


*/
	return TRUE;  // return TRUE  unless you set the focus to a control
}



void CAdoTestDlg::OnBtncreatedb() 
{
	// TODO: Add your control notification handler code here
	WCHAR db[256];

	UpdateData();
	wsprintf(db,L"\\%ls.cdb",m_strDB);

	if(!m_db.CreateDatabase(db))
		MessageBox(L"Create Database Error");
}

void CAdoTestDlg::OnBtnopendb() 
{
	// TODO: Add your control notification handler code here
	WCHAR db[256];

	UpdateData();
	wsprintf(db,L"\\%ls.cdb",m_strDB);

	if(!m_db.OpenDB(db,L"",L""))
		MessageBox(L"Open Database Error");
}

void CAdoTestDlg::OnBtnclosedb() 
{
	// TODO: Add your control notification handler code here
	m_db.CloseDB();
}

void CAdoTestDlg::OnBtnadditem() 
{
	// TODO: Add your control notification handler code here
	UpdateData();

	WCHAR strSql[256];
	UpdateData();
	wsprintf(strSql,L"INSERT INTO %ls(itemid,amount) VALUES(%ls,%ls)",
			 m_strTable,
			 m_strFld1,m_strFld2);
	if(!m_db.Query(strSql))
		MessageBox(L"Query Error");
}

void CAdoTestDlg::OnBtnprev() 
{
	// TODO: Add your control notification handler code here
	VARIANT_BOOL bBOF;
	m_pRS->MovePrevious();
	m_pRS->get_BOF(&bBOF);
	UpdateFileds();
	if(bBOF)
	{
		MessageBox(L"BOF");
	}
}

void CAdoTestDlg::OnBtnnext() 
{
	// TODO: Add your control notification handler code here
	VARIANT_BOOL bEOF;
	m_pRS->MoveNext();
	m_pRS->get_EOF(&bEOF);
	UpdateFileds();
	if(bEOF)
	{
		MessageBox(L"EOF");
	}
}

void CAdoTestDlg::OnBtncreatetbl() 
{
	// TODO: Add your control notification handler code here
	WCHAR tbl[256];

	UpdateData();
	wsprintf(tbl,L"CREATE TABLE %ls(itemid integer,amount integer)",m_strTable);

	if(!m_db.Query(tbl))
		MessageBox(L"Create Table Error");
}

void CAdoTestDlg::OnBtnopentbl() 
{
	// TODO: Add your control notification handler code here
	WCHAR tbl[256];

	UpdateData();
	wsprintf(tbl,L"SELECT * FROM %ls",m_strTable);

	if(m_pRS != NULL)
	{
		m_pRS->Close();
		m_pRS.Release();
	}
	if(!m_db.Query(tbl,&m_pRS))
		MessageBox(L"Quer Error");
	else
		UpdateFileds();
}

void CAdoTestDlg::OnBtnclosetbl() 
{
	// TODO: Add your control notification handler code here
	m_pRS->Close();
}

void CAdoTestDlg::UpdateFileds()
{
	VARIANT vId;
	vId.vt=VT_I4;
	CComPtr<Fields> flds;
	CComPtr<Field> fld1,fld2;
	m_pRS->get_Fields(&flds);

	if(flds == NULL)
		return;

	vId.lVal=0;
	flds->get_Item(vId,&fld1);

	vId.lVal=1;
	flds->get_Item(vId,&fld2);

	if(fld1 == NULL || fld2 == NULL)
		return;

	COleVariant vFld1,vFld2;

	fld1->get_Value(&vFld1);
	fld2->get_Value(&vFld2);

	vFld1.ChangeType(VT_BSTR);
	vFld2.ChangeType(VT_BSTR);

	m_strFld1=vFld1.bstrVal;
	m_strFld2=vFld2.bstrVal;

	UpdateData(FALSE);
}

void CAdoTestDlg::OnBtnexe() 
{
	// TODO: Add your control notification handler code here
	UpdateData();

	WCHAR strSql[256];
	wsprintf(strSql,L"%ls",m_strSql);

	if(!m_db.Query(strSql))
	{
		MessageBox(L"Quer Error");
	}
}

void CAdoTestDlg::OnOK() 
{
	// TODO: Add extra validation here
	
	//CDialog::OnOK();

	PostQuitMessage(0);
}

void CAdoTestDlg::OnBtnexit() 
{
	// TODO: Add your control notification handler code here
	PostQuitMessage(0);
}

⌨️ 快捷键说明

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