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

📄 store.cpp

📁 这个一个VC连接MSSQL数据库的小软件
💻 CPP
字号:
// Store.cpp : implementation file
//

#include "stdafx.h"
#include "Rent.h"
#include "Store.h"

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

/////////////////////////////////////////////////////////////////////////////
// CStore dialog


CStore::CStore(CWnd* pParent /*=NULL*/)
	: CDialog(CStore::IDD, pParent)
{
	//{{AFX_DATA_INIT(CStore)
	m_dvdname = _T("");
	m_dvdnum = _T("");
	m_dvdnote = _T("");
	//}}AFX_DATA_INIT
}


void CStore::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CStore)
	DDX_Text(pDX, IDC_EDIT_NAME, m_dvdname);
	DDX_Text(pDX, IDC_EDIT_num, m_dvdnum);
	DDX_LBString(pDX, IDC_LIST_note, m_dvdnote);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CStore, CDialog)
	//{{AFX_MSG_MAP(CStore)
	ON_WM_CANCELMODE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CStore message handlers
BOOL CStore::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	//初始化数据库连接
	HRESULT hr;
	try
	{
		//实例化连接对象
		hr=m_pConnection.CreateInstance(__uuidof(Connection));
		if(SUCCEEDED(hr))
		{
			//设置连接串属性为UDL文件
			m_pConnection->ConnectionString="File Name=my_data1.udl";
			//设置等待连接打开的时间为20s
			m_pConnection->ConnectionTimeout=20;
			hr=m_pConnection->Open("","","",adConnectUnspecified);
			if(FAILED(hr))
			{
				AfxMessageBox("no open fail!");
				return TRUE;
			}
		}
		else
		{
			AfxMessageBox("createinsrance of Connection fail!");
			return TRUE;
		}
	}
	catch(_com_error e)
	{
		//给出异常信息
		_bstr_t bstrSource(e.Source());
		_bstr_t bstrDescription(e.Description());
		AfxMessageBox(bstrSource+bstrDescription);
		return TRUE;
	}
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CStore::OnCancelMode() 
{
	CDialog::OnCancelMode();
	
	// TODO: Add your message handler code here
	
}

⌨️ 快捷键说明

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