?? querydel.cpp
字號:
// QueryDel.cpp : 實現文件
//
#include "stdafx.h"
#include "AS.h"
#include "QueryDel.h"
// CQueryDel 對話框
IMPLEMENT_DYNAMIC(CQueryDel, CDialog)
CQueryDel::CQueryDel(CWnd* pParent /*=NULL*/)
: CDialog(CQueryDel::IDD, pParent)
, m_sName(_T(""))
, m_sKey(_T(""))
{
}
CQueryDel::~CQueryDel()
{
}
void CQueryDel::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDIT1, m_sName);
DDX_Text(pDX, IDC_EDIT2, m_sKey);
}
BEGIN_MESSAGE_MAP(CQueryDel, CDialog)
ON_EN_CHANGE(IDC_EDIT1, &CQueryDel::OnEnChangeEdit1)
ON_EN_CHANGE(IDC_EDIT2, &CQueryDel::OnEnChangeEdit2)
ON_BN_CLICKED(IDC_BUTTON1, &CQueryDel::OnBnClickedButton1)
ON_BN_CLICKED(IDC_BUTTON2, &CQueryDel::OnBnClickedButton2)
ON_BN_CLICKED(IDC_BUTTON4, &CQueryDel::OnBnClickedButton4)
END_MESSAGE_MAP()
// CQueryDel 消息處理程序
void CQueryDel::OnEnChangeEdit1()
{
// TODO: 如果該控件是 RICHEDIT 控件,則它將不會
// 發送該通知,除非重寫 CDialog::OnInitDialog()
// 函數并調用 CRichEditCtrl().SetEventMask(),
// 同時將 ENM_CHANGE 標志“或”運算到掩碼中。
// TODO: 在此添加控件通知處理程序代碼
UpdateData(TRUE);
}
void CQueryDel::OnEnChangeEdit2()
{
// TODO: 如果該控件是 RICHEDIT 控件,則它將不會
// 發送該通知,除非重寫 CDialog::OnInitDialog()
// 函數并調用 CRichEditCtrl().SetEventMask(),
// 同時將 ENM_CHANGE 標志“或”運算到掩碼中。
// TODO: 在此添加控件通知處理程序代碼
UpdateData(TRUE);
}
void CQueryDel::OnBnClickedButton1()
{
// TODO: 在此添加控件通知處理程序代碼
//用于連接數據庫
HRESULT hr = S_OK;
_ConnectionPtr pConn = NULL;
_RecordsetPtr pRst = NULL;
TCHAR szExePath[400] = {'\0'};
PTCHAR pLast = NULL;
//連接字符串
CString strOpen;
strOpen = "DRIVER={Microsoft Access Driver (*.mdb)};UID=;PWD=;DBQ=Person.mdb";
//查詢語句
CString strQuery;
CString sTemp;
//初始化連接
CoInitialize(NULL);
hr = pConn.CreateInstance(__uuidof(Connection));
if(hr != S_OK)
{
AfxMessageBox(_T("打開Connection失敗"));
return;
}
hr = S_OK;
//設置exe文件所在路徑為當前路徑
GetModuleFileName(NULL,szExePath,400);
if(pLast = _tcsstr(szExePath,_T("\\AS.exe")))
{
*pLast = '\0';
}
SetCurrentDirectory(szExePath);
//連接數據庫
try
{
pConn->Open((_bstr_t)strOpen,"","",adConnectUnspecified);
}
catch(_com_error e)
{
AfxMessageBox(_T("Opening Connection...")+e.Description());
return;
}
strQuery.Format(_T("insert into User(Name,Key) values(\'%s\',\'%s\')"),m_sName,m_sKey);
pRst = pConn->Execute((_bstr_t)strQuery,NULL,adCmdText);
AfxMessageBox(_T("添加成功"));
//關閉數據庫
try
{
pConn->Close();
}
catch(_com_error e)
{
AfxMessageBox(_T("Closing Connection...")+e.Description());
return;
}
pConn.Release();
CoUninitialize();
OnCancel();
return;
}
void CQueryDel::OnBnClickedButton2()
{
// TODO: 在此添加控件通知處理程序代碼
//用于連接數據庫
HRESULT hr = S_OK;
_ConnectionPtr pConn = NULL;
_RecordsetPtr pRst = NULL;
TCHAR szExePath[400] = {'\0'};
PTCHAR pLast = NULL;
//連接字符串
CString strOpen;
strOpen = "DRIVER={Microsoft Access Driver (*.mdb)};UID=;PWD=;DBQ=Person.mdb";
//查詢語句
CString strQuery;
CString sTemp;
//初始化連接
CoInitialize(NULL);
hr = pConn.CreateInstance(__uuidof(Connection));
if(hr != S_OK)
{
AfxMessageBox(_T("打開Connection失敗"));
return;
}
hr = S_OK;
//設置exe文件所在路徑為當前路徑
GetModuleFileName(NULL,szExePath,400);
if(pLast = _tcsstr(szExePath,_T("\\AS.exe")))
{
*pLast = '\0';
}
SetCurrentDirectory(szExePath);
//連接數據庫
try
{
pConn->Open((_bstr_t)strOpen,"","",adConnectUnspecified);
}
catch(_com_error e)
{
AfxMessageBox(_T("Opening Connection...")+e.Description());
return;
}
strQuery.Format(_T("delete from User where Name=\'%s\'"),m_sName);
pRst = pConn->Execute((_bstr_t)strQuery,NULL,adCmdText);
AfxMessageBox(_T("刪除成功"));
//關閉數據庫
try
{
pConn->Close();
}
catch(_com_error e)
{
AfxMessageBox(_T("Closing Connection...")+e.Description());
return;
}
pConn.Release();
CoUninitialize();
OnCancel();
return;
}
void CQueryDel::OnBnClickedButton4()
{
// TODO: 在此添加控件通知處理程序代碼
OnCancel();
return;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -