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

📄 raindbaccess.cpp

📁 用C++基于SQL SERVER使用存储过程
💻 CPP
字号:
// RainDBAccess.cpp: implementation of the RainDBAccess class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "RainDBAccess.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

RainDBAccess::RainDBAccess()
{

}

RainDBAccess::~RainDBAccess()
{

}
/*
int RainDBAccess::startbr()
{
	int intReturnCode=0;

	if(!m_fConnected){
		m_strErrMsg="***错误:数据库尚未连接";
		return -1;
	}

	HRESULT			hr;
	_bstr_t			source=m_strSource;
	_bstr_t			query=m_strSQL;
	try{
		hr=m_pRst->Open(query,source,adOpenDynamic,adLockOptimistic,adCmdText);
	}
	catch(_com_error e){
		m_strErrMsg.Format("***错误:打开记录集出错:%s",e.ErrorMessage());
		return -1;
	}

	intReturnCode=bindvalue();
	if(intReturnCode<0)m_strErrMsg="***错误:获取表栏位值出错";
	return intReturnCode;
}

int RainDBAccess::readnext()
{
	int intReturnCode=0;

	if(!m_fConnected){
		m_strErrMsg="***错误:数据库尚未连接";
		return -1;
	}

	try{
		m_pRst->MoveNext();
	}
	catch(_com_error e){
		m_strErrMsg.Format("***错误:记录集读取次笔出错:%s",e.ErrorMessage());
		return -1;
	}

	intReturnCode=bindvalue();
	if(intReturnCode<0)m_strErrMsg="***错误:获取表栏位值出错";
	return intReturnCode;
}

int RainDBAccess::endbr()
{
	if(!m_fConnected)return -1;
	m_pRst->Close();
	return 0;
}

int RainDBAccess::insertrec()
{
	int intReturnCode=0;
	
	if(!m_fConnected){
		m_strErrMsg="***错误:数据库尚未连接";
		return -1;
	}

	HRESULT			hr;

	try{
		hr=m_pRst->AddNew();
		intReturnCode=setvalue();
		if(intReturnCode<0){
			m_strErrMsg="***错误:设置表栏位值出错";
			return intReturnCode;
		}

		hr=m_pRst->Update();
	}
	catch(_com_error e){
		m_strErrMsg.Format("***错误:新增记录出错:%s",e.ErrorMessage());
		return -1;
	}

	return 0;
}

int RainDBAccess::updaterec()
{
	int intReturnCode=0;

	HRESULT			hr;

	if(!m_fConnected){
		m_strErrMsg="***错误:数据库尚未连接";
		return -1;
	}

	if(m_pRst->EndOfFile){
		m_strErrMsg="   警告:记录集到尾";
		return 1;
	}

	try{
		intReturnCode=setvalue();
		if(intReturnCode<0){
			m_strErrMsg="***错误:设置表栏位值出错";
			return intReturnCode;
		}
		hr=m_pRst->Update();
	}
	catch(_com_error e){
		m_strErrMsg.Format("***错误:更新数据出错%s",e.ErrorMessage());
		return -1;
	}

	return 0;
}

int RainDBAccess::deleterec()
{
	int intReturnCode=0;

	HRESULT			hr;

	if(!m_fConnected){
		m_strErrMsg="***错误:数据库尚未连接";
		return -1;
	}

	if(m_pRst->EndOfFile){
		m_strErrMsg="   警告:记录集到尾";
		return 1;
	}

	try{
		hr=m_pRst->Delete(adAffectCurrent);
	}
	catch(_com_error e){
		m_strErrMsg.Format("***错误:删除数据出错:%s",e.ErrorMessage());
		return -1;
	}

	return 0;
}
*/
int RainDBAccess::setvalue()
{
	VARIANT			varValue;
	CString			strValue;

	try{
		varValue.vt=VT_BSTR;
		varValue.bstrVal=(_bstr_t)m_strInputTime;
		m_pRst->PutCollect("datatime",&varValue);

		varValue.vt=VT_BSTR;
		strValue.Format("%f",m_dblInputVal);
		varValue.bstrVal=(_bstr_t)strValue;
		m_pRst->PutCollect("rainfallinfo",&varValue);

		varValue.vt=VT_I4;
		varValue.iVal=m_intPeriods;
		m_pRst->PutCollect("periods",&varValue);

		varValue.vt=VT_BSTR;
		varValue.bstrVal=(_bstr_t)m_strInputMode;
		m_pRst->PutCollect("inputmode",&varValue);
	}
	catch(_com_error e){
		return -1;
	}
	return 0;
}

int RainDBAccess::bindvalue()
{
	if(m_pRst->EndOfFile)return 1;

	VARIANT			varValue;
	try{
		varValue = m_pRst->GetCollect("datatime");
		if(varValue.vt != VT_NULL)m_strInputTime=(LPCSTR)_bstr_t(varValue);

		varValue = m_pRst->GetCollect("rainfallinfo");
		if(varValue.vt != VT_NULL)m_dblInputVal=atof((LPCSTR)_bstr_t(varValue));

		varValue = m_pRst->GetCollect("periods");
		if(varValue.vt != VT_NULL)m_intPeriods=varValue.intVal;

		varValue = m_pRst->GetCollect("inputmode");
		if(varValue.vt != VT_NULL)m_strInputMode=(LPCSTR)_bstr_t(varValue);
	}
	catch(_com_error e){
		return -1;
	}
	return 0;
}

⌨️ 快捷键说明

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