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

📄 addemployee.cpp

📁 使用MFC界面连SQL2000实现管理操作
💻 CPP
字号:
// AddEmployee.cpp : implementation file
//

#include "stdafx.h"
#include "数据库实践.h"
#include "AddEmployee.h"

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

/////////////////////////////////////////////////////////////////////////////
// AddEmployee dialog


AddEmployee::AddEmployee(CWnd* pParent /*=NULL*/)
	: CDialog(AddEmployee::IDD, pParent)
{
	//{{AFX_DATA_INIT(AddEmployee)
	m_employeeid = 0;
	m_employeename = _T("");
	m_employeeage = 0;
	m_employeeworkage = 0;
	//}}AFX_DATA_INIT
}


void AddEmployee::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(AddEmployee)
	DDX_Text(pDX, IDC_EDIT1, m_employeeid);
	DDX_Text(pDX, IDC_EDIT2, m_employeename);
	DDX_Text(pDX, IDC_EDIT3, m_employeeage);
	DDX_Text(pDX, IDC_EDIT4, m_employeeworkage);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(AddEmployee, CDialog)
	//{{AFX_MSG_MAP(AddEmployee)
	ON_BN_CLICKED(IDC_BUTTON2, OnSubmit)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// AddEmployee message handlers

void AddEmployee::OnSubmit() 
{
	// TODO: Add your control notification handler code here
	
	_ConnectionPtr pConn;
	_CommandPtr pCmd;
	_RecordsetPtr pRst;
   
	CoInitialize(NULL);
	
	pConn.CreateInstance(__uuidof(Connection));//
	pCmd.CreateInstance((__uuidof(Command)));
	pRst.CreateInstance((__uuidof(Recordset)));
	//connection string
	
	pConn->ConnectionString="Provider=SQLOLEDB.1;Password=123456;Persist Security Info=TRUE;User ID=sa;Initial Catalog=超市管理系统";
	//open connection
	try
	{
		pConn->Open("","","",adConnectUnspecified);
	}
	catch(_com_error e)
	{
		AfxMessageBox(e.ErrorMessage());
	}

	UpdateData(true);
	CString str;	

	UpdateData(true);
	str.Format("exec add_employee %d,'%s',%d,%d",this->m_employeeid,this->m_employeename,this->m_employeeage,this->m_employeeworkage);
	_variant_t   RecordsAffected; 
	AfxMessageBox(str);
	try
	{
 	    pConn->Execute((_bstr_t)str,NULL,adCmdText);
	
	}
	catch(_com_error e)
	{
		AfxMessageBox(e.ErrorMessage());
	
	}


	AfxMessageBox("增加成功!");
	pConn->Close();
	CDialog::OnOK();
	
}

⌨️ 快捷键说明

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