ado.cpp

来自「一个完整的VC对数据库操作的实例」· C++ 代码 · 共 2,060 行 · 第 1/5 页

CPP
2,060
字号
BOOL CAdoRecordSet::PutCollect(long index, const double &value)
{
	ASSERT(m_pRecordset != NULL);
	#ifdef _DEBUG
	if (GetFieldType(index) != adDouble)
	AfxMessageBox("你要存储的字段与变量的数据类型不符");
	#endif
	ASSERT(GetFieldType(index) == adDouble);

	return PutCollect(index, _variant_t(value));
}

BOOL CAdoRecordSet::PutCollect(LPCTSTR strFieldName, const LPCTSTR &value)
{
	ASSERT(m_pRecordset != NULL);
	#ifdef _DEBUG
	if (! (GetFieldType(strFieldName) == adVarChar
		|| GetFieldType(strFieldName) == adChar
		|| GetFieldType(strFieldName) == adLongVarChar))
	AfxMessageBox("你要存储的字段与变量的数据类型不符");
	#endif
	ASSERT(GetFieldType(strFieldName) == adVarChar
		|| GetFieldType(strFieldName) == adChar
		|| GetFieldType(strFieldName) == adLongVarChar);
	
	return PutCollect(strFieldName, _variant_t(value));
}

BOOL CAdoRecordSet::PutCollect(LPCTSTR strFieldName, const BYTE &value)
{
	ASSERT(m_pRecordset != NULL);
	#ifdef _DEBUG
	if (GetFieldType(strFieldName) != adUnsignedTinyInt)
	AfxMessageBox("你要存储的字段与变量的数据类型不符");
	#endif
	ASSERT(GetFieldType(strFieldName) == adUnsignedTinyInt);
	
	return PutCollect(strFieldName, _variant_t(value));
}

BOOL CAdoRecordSet::PutCollect(LPCTSTR strFieldName, const short &value)
{
	ASSERT(m_pRecordset != NULL);
	#ifdef _DEBUG
	if (GetFieldType(strFieldName) != adSmallInt)
	AfxMessageBox("你要存储的字段与变量的数据类型不符");
	#endif
	ASSERT(GetFieldType(strFieldName) == adSmallInt);
	return PutCollect(strFieldName, _variant_t(value));
}

BOOL CAdoRecordSet::PutCollect(LPCTSTR strFieldName, const int &value)
{
	ASSERT(m_pRecordset != NULL);
	
	#ifdef _DEBUG
	if (GetFieldType(strFieldName) != adInteger)
	AfxMessageBox("你要存储的字段与变量的数据类型不符");
	#endif
	ASSERT(GetFieldType(strFieldName) == adInteger);

	return PutCollect(strFieldName, _variant_t(long(value)));
}

BOOL CAdoRecordSet::PutCollect(LPCTSTR strFieldName, const long &value)
{
	ASSERT(m_pRecordset != NULL);
	#ifdef _DEBUG
	if (GetFieldType(strFieldName) != adBigInt)
	AfxMessageBox("你要存储的字段与变量的数据类型不符");
	#endif
	ASSERT(GetFieldType(strFieldName) == adBigInt);
	
	return PutCollect(strFieldName, _variant_t(value));
}

BOOL CAdoRecordSet::PutCollect(LPCTSTR strFieldName, const float &value)
{
	ASSERT(m_pRecordset != NULL);
	#ifdef _DEBUG
	if (GetFieldType(strFieldName) != adSingle)
	AfxMessageBox("你要存储的字段与变量的数据类型不符");
	#endif
	ASSERT(GetFieldType(strFieldName) == adSingle);

	return PutCollect(strFieldName, _variant_t(value));
}

BOOL CAdoRecordSet::PutCollect(LPCTSTR strFieldName, const double &value)
{
	ASSERT(m_pRecordset != NULL);
	#ifdef _DEBUG
	if (GetFieldType(strFieldName) != adDouble)
	AfxMessageBox("你要存储的字段与变量的数据类型不符");
	#endif
	ASSERT(GetFieldType(strFieldName) == adDouble);
	
	return PutCollect(strFieldName, _variant_t(value));
}

/*########################################################################
			  ------------------------------------------------
							       数据存取
			  ------------------------------------------------
  ########################################################################*/

BOOL CAdoRecordSet::GetCollect(long index,  BYTE &value)
{
	ASSERT(m_pRecordset != NULL);
	#ifdef _DEBUG
	if (GetFieldType(index) != adUnsignedTinyInt)
	AfxMessageBox("你要读取的字段与变量的数据类型不符");
	#endif
	ASSERT(GetFieldType(index) == adUnsignedTinyInt);

	try
	{
		if (m_pRecordset != NULL) 
		{
			_variant_t result = m_pRecordset->GetCollect(_variant_t(index));
			value = result.bVal;
			return TRUE;
		}
	}
	catch (_com_error e)
	{
		return FALSE;
	} 	
	return FALSE;
}

BOOL CAdoRecordSet::GetCollect(long index,  short &value)
{
	ASSERT(m_pRecordset != NULL);
	ASSERT(m_pRecordset != NULL);
	#ifdef _DEBUG
	if (GetFieldType(index) != adSmallInt)
	AfxMessageBox("你要读取的字段与变量的数据类型不符");
	#endif
	ASSERT(GetFieldType(index) == adSmallInt);

	try
	{
		if (m_pRecordset != NULL) 
		{
			_variant_t result = m_pRecordset->GetCollect(_variant_t(index));
			value = result.iVal;
			return TRUE;
		}
	}
	catch (_com_error e)
	{
		return FALSE;
	} 	
	return FALSE;
}

BOOL CAdoRecordSet::GetCollect(long index,  int &value)
{
	ASSERT(m_pRecordset != NULL);
	#ifdef _DEBUG
	if (GetFieldType(index) != adInteger)
	AfxMessageBox("你要读取的字段与变量的数据类型不符");
	#endif
	ASSERT(GetFieldType(index) == adInteger);

	try
	{
		if (m_pRecordset != NULL) 
		{
			_variant_t result = m_pRecordset->GetCollect(_variant_t(index));
			value = result.intVal;
			return TRUE;
		}
	}
	catch (_com_error e)
	{
		return FALSE;
	} 	
	return FALSE;
}

BOOL CAdoRecordSet::GetCollect(long index,  long &value)
{
	ASSERT(m_pRecordset != NULL);
	#ifdef _DEBUG
	if (GetFieldType(index) != adBigInt)
	AfxMessageBox("你要读取的字段与变量的数据类型不符");
	#endif
	ASSERT(GetFieldType(index) == adBigInt);

	try
	{
		if (m_pRecordset != NULL) 
		{
			_variant_t result = m_pRecordset->GetCollect(_variant_t(index));
			value = result.lVal;
			return TRUE;
		}
	}
	catch (_com_error e)
	{
		return FALSE;
	} 	
	return FALSE;
}

BOOL CAdoRecordSet::GetCollect(long index,  float &value)
{
	ASSERT(m_pRecordset != NULL);
	#ifdef _DEBUG
	if (GetFieldType(index) != adSingle)
	AfxMessageBox("你要读取的字段与变量的数据类型不符");
	#endif
	ASSERT(GetFieldType(index) == adSingle);

	try
	{
		if (m_pRecordset != NULL) 
		{
			_variant_t result = m_pRecordset->GetCollect(_variant_t(index));
			value = result.fltVal;
			return TRUE;
		}
	}
	catch (_com_error e)
	{
		return FALSE;
	} 	
	return FALSE;
}

BOOL CAdoRecordSet::GetCollect(long index,  double &value)
{
	ASSERT(m_pRecordset != NULL);
	#ifdef _DEBUG
	if (GetFieldType(index) != adDouble)
	AfxMessageBox("你要读取的字段与变量的数据类型不符");
	#endif
	ASSERT(GetFieldType(index) == adDouble);

	try
	{
		if (m_pRecordset != NULL) 
		{
			_variant_t result = m_pRecordset->GetCollect(_variant_t(index));
			value = result.dblVal;
			return TRUE;
		}
	}
	catch (_com_error e)
	{
		return FALSE;
	} 	
	return FALSE;
}

BOOL CAdoRecordSet::GetCollect(LPCSTR strFieldName,  BYTE &value)
{
	ASSERT(m_pRecordset != NULL);
	#ifdef _DEBUG
	if (GetFieldType(strFieldName) != adUnsignedTinyInt)
	AfxMessageBox("你要读取的字段与变量的数据类型不符");
	#endif
	ASSERT(GetFieldType(strFieldName) == adUnsignedTinyInt);

	try
	{
		if (m_pRecordset != NULL) 
		{
			_variant_t result = m_pRecordset->GetCollect(_variant_t(strFieldName));
			value = result.bVal;
			return TRUE;
		}
	}
	catch (_com_error e)
	{
		return FALSE;
	} 	
	return FALSE;
}

BOOL CAdoRecordSet::GetCollect(LPCSTR strFieldName,  short &value)
{
	ASSERT(m_pRecordset != NULL);
	#ifdef _DEBUG
	if (GetFieldType(strFieldName) != adSmallInt)
	AfxMessageBox("你要读取的字段与变量的数据类型不符");
	#endif
	ASSERT(GetFieldType(strFieldName) == adSmallInt);

	try
	{
		if (m_pRecordset != NULL) 
		{
			_variant_t result = m_pRecordset->GetCollect(_variant_t(strFieldName));
			value = result.iVal;
			return TRUE;
		}
	}
	catch (_com_error e)
	{
		return FALSE;
	} 	
	return FALSE;
}

BOOL CAdoRecordSet::GetCollect(LPCSTR strFieldName,  int &value)
{
	ASSERT(m_pRecordset != NULL);
	#ifdef _DEBUG
	if (GetFieldType(strFieldName) != adInteger)
	AfxMessageBox("你要读取的字段与变量的数据类型不符");
	#endif
	ASSERT(GetFieldType(strFieldName) == adInteger);

	try
	{
		if (m_pRecordset != NULL) 
		{
			_variant_t result = m_pRecordset->GetCollect(_variant_t(strFieldName));
			value = result.intVal;
			return TRUE;
		}
	}
	catch (_com_error e)
	{
		return FALSE;
	} 	
	return FALSE;
}

BOOL CAdoRecordSet::GetCollect(LPCSTR strFieldName,  long &value)
{
	ASSERT(m_pRecordset != NULL);
	#ifdef _DEBUG
	if (GetFieldType(strFieldName) != adBigInt)
	AfxMessageBox("你要读取的字段与变量的数据类型不符");
	#endif
	ASSERT(GetFieldType(strFieldName) == adBigInt);

	try
	{
		if (m_pRecordset != NULL) 
		{
			_variant_t result = m_pRecordset->GetCollect(_variant_t(strFieldName));
			value = result.lVal;
			return TRUE;
		}
	}
	catch (_com_error e)
	{
		return FALSE;
	} 	
	return FALSE;
}

BOOL CAdoRecordSet::GetCollect(LPCSTR strFieldName,  float &value)
{
	ASSERT(m_pRecordset != NULL);
	#ifdef _DEBUG
	if (GetFieldType(strFieldName) != adSingle)
	AfxMessageBox("你要读取的字段与变量的数据类型不符");
	#endif
	ASSERT(GetFieldType(strFieldName) == adSingle);

	try
	{
		if (m_pRecordset != NULL) 
		{
			_variant_t result = m_pRecordset->GetCollect(_variant_t(strFieldName));
			value = result.fltVal;
			return TRUE;
		}
	}
	catch (_com_error e)
	{
		return FALSE;
	} 	
	return FALSE;
}

BOOL CAdoRecordSet::GetCollect(LPCSTR strFieldName,  double &value)
{
	ASSERT(m_pRecordset != NULL);
	#ifdef _DEBUG
	if (GetFieldType(strFieldName) != adDouble)
	AfxMessageBox("你要读取的字段与变量的数据类型不符");
	#endif
	ASSERT(GetFieldType(strFieldName) == adDouble);

	try
	{
		if (m_pRecordset != NULL) 
		{
			_variant_t result = m_pRecordset->GetCollect(_variant_t(strFieldName));
			value = result.dblVal;
			return TRUE;
		}
	}
	catch (_com_error e)
	{
		return FALSE;
	} 	
	return FALSE;
}

BOOL CAdoRecordSet::GetCollect(long index,  CString &value)
{
	ASSERT(m_pRecordset != NULL);
	#ifdef _DEBUG
	if (! (GetFie

⌨️ 快捷键说明

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