📄 adorecordset.cpp
字号:
ASSERT(m_pRecordset != NULL);
try
{
return m_pRecordset->Fields->GetItem(_variant_t(lIndex))->GetType();
}
catch (_com_error e)
{
m_errormessage.Format(_T("Warning: GetField 方法发生异常. 错误信息: %s; 文件: %s; 行: %d\n"), e.ErrorMessage(), __FILE__, __LINE__);
AfxMessageBox(m_errormessage);
return adEmpty;
}
}
DataTypeEnum CAdoRecordSet::GetFieldType(LPCTSTR lpszFieldName)
{
ASSERT(m_pRecordset != NULL);
try
{
return m_pRecordset->Fields->GetItem(_variant_t(lpszFieldName))->GetType();
}
catch (_com_error e)
{
m_errormessage.Format(_T("Warning: GetField发生异常. 错误信息: %s; 文件: %s; 行: %d\n"), e.ErrorMessage(), __FILE__, __LINE__);
AfxMessageBox(m_errormessage);
return adEmpty;
}
}
BOOL CAdoRecordSet::IsFieldNull(LPCTSTR lpFieldName)
{
try
{
_variant_t vt = m_pRecordset->Fields->GetItem(lpFieldName)->Value;
return (vt.vt == VT_NULL);
}
catch (_com_error e)
{
m_errormessage.Format(_T("Warning: IsFieldNull 方法发生异常. 错误信息: %s; 文件: %s; 行: %d\n"), e.ErrorMessage(), __FILE__, __LINE__);
AfxMessageBox(m_errormessage);
return FALSE;
}
}
BOOL CAdoRecordSet::IsFieldNull(long index)
{
try
{
_variant_t vt = m_pRecordset->Fields->GetItem(_variant_t(index))->Value;
return (vt.vt == VT_NULL);
}
catch (_com_error e)
{
m_errormessage.Format(_T("Warning: IsFieldNull 方法发生异常. 错误信息: %s; 文件: %s; 行: %d\n"), e.ErrorMessage(), __FILE__, __LINE__);
AfxMessageBox(m_errormessage);
return FALSE;
}
}
/*========================================================================
Name: 取得指定列的字段对象的指针.
==========================================================================*/
FieldPtr CAdoRecordSet::GetField(long lIndex)
{
try
{
return GetFields()->GetItem(_variant_t(lIndex));
}
catch (_com_error e)
{
m_errormessage.Format(_T("Warning: GetField发生异常. 错误信息: %s; 文件: %s; 行: %d\n"), e.ErrorMessage(), __FILE__, __LINE__);
AfxMessageBox(m_errormessage);
return NULL;
}
}
FieldPtr CAdoRecordSet::GetField(LPCTSTR lpszFieldName)
{
try
{
return GetFields()->GetItem(_variant_t(lpszFieldName));
}
catch (_com_error e)
{
m_errormessage.Format(_T("Warning: GetField发生异常. 错误信息: %s; 文件: %s; 行: %d\n"), e.ErrorMessage(), __FILE__, __LINE__);
AfxMessageBox(m_errormessage);
return NULL;
}
}
/*------------------------------------------------
设置字段的值
------------------------------------------------*/
BOOL CAdoRecordSet::PutCollect(long index, const _variant_t &value)
{
ASSERT(m_pRecordset != NULL);
ASSERT(index < GetFieldsCount());
try
{
if (m_pRecordset != NULL)
{
m_pRecordset->PutCollect(_variant_t(index), value);
return TRUE;
}
}
catch (_com_error e)
{
m_errormessage.Format(_T("Warning: PutCollect 方法发生异常. 错误信息: %s; 文件: %s; 行: %d\n"), e.ErrorMessage(), __FILE__, __LINE__);
AfxMessageBox(m_errormessage);
return FALSE;
}
return FALSE;
}
BOOL CAdoRecordSet::PutCollect(LPCSTR strFieldName, const _variant_t &value)
{
ASSERT(m_pRecordset != NULL);
try
{
if (m_pRecordset != NULL)
{
m_pRecordset->put_Collect(_variant_t(strFieldName), value);
return TRUE;
}
}
catch (_com_error e)
{
m_errormessage.Format(_T("Warning: PutCollect 方法发生异常. 错误信息: %s; 文件: %s; 行: %d\n"), e.ErrorMessage(), __FILE__, __LINE__);
AfxMessageBox(m_errormessage);
return FALSE;
}
return FALSE;
}
BOOL CAdoRecordSet::PutCollect(long index, const bool &value)
{
ASSERT(m_pRecordset != NULL);
#ifdef _DEBUG
if (GetFieldType(index) != adBoolean){
m_errormessage.Format(_T("Warning: 你要存贮的字段与变量的数据类型不符; 文件: %s; 行: %d\n"), __FILE__, __LINE__);
AfxMessageBox(m_errormessage);
}
#endif
return PutCollect(index, _variant_t(value));
}
BOOL CAdoRecordSet::PutCollect(LPCTSTR strFieldName, const bool &value)
{
ASSERT(m_pRecordset != NULL);
#ifdef _DEBUG
if (GetFieldType(strFieldName) != adBoolean){
m_errormessage.Format(_T("Warning: 你要存贮的字段与变量的数据类型不符; 文件: %s; 行: %d\n"), __FILE__, __LINE__);
AfxMessageBox(m_errormessage);
}
#endif
return PutCollect(strFieldName, _variant_t(value));
}
BOOL CAdoRecordSet::PutCollect(long index, const BYTE &value)
{
ASSERT(m_pRecordset != NULL);
#ifdef _DEBUG
if (GetFieldType(index) != adUnsignedTinyInt){
m_errormessage.Format(_T("Warning: 你要存贮的字段与变量的数据类型不符; 文件: %s; 行: %d\n"), __FILE__, __LINE__);
AfxMessageBox(m_errormessage);
}
#endif
return PutCollect(index, _variant_t(value));
}
BOOL CAdoRecordSet::PutCollect(LPCTSTR strFieldName, const BYTE &value)
{
ASSERT(m_pRecordset != NULL);
#ifdef _DEBUG
if (GetFieldType(strFieldName) != adUnsignedTinyInt){
m_errormessage.Format(_T("Warning: 你要存贮的字段与变量的数据类型不符; 文件: %s; 行: %d\n"), __FILE__, __LINE__);
AfxMessageBox(m_errormessage);
}
#endif
return PutCollect(strFieldName, _variant_t(value));
}
BOOL CAdoRecordSet::PutCollect(long index, const short &value)
{
ASSERT(m_pRecordset != NULL);
#ifdef _DEBUG
if (GetFieldType(index) != adSmallInt){
m_errormessage.Format(_T("Warning: 你要存贮的字段与变量的数据类型不符; 文件: %s; 行: %d\n"), __FILE__, __LINE__);
AfxMessageBox(m_errormessage);
}
#endif
return PutCollect(index, _variant_t(value));
}
BOOL CAdoRecordSet::PutCollect(LPCTSTR strFieldName, const short &value)
{
ASSERT(m_pRecordset != NULL);
#ifdef _DEBUG
if (GetFieldType(strFieldName) != adSmallInt){
m_errormessage.Format(_T("Warning: 你要存贮的字段与变量的数据类型不符; 文件: %s; 行: %d\n"), __FILE__, __LINE__);
AfxMessageBox(m_errormessage);
}
#endif
return PutCollect(strFieldName, _variant_t(value));
}
BOOL CAdoRecordSet::PutCollect(long index, const int &value)
{
ASSERT(m_pRecordset != NULL);
#ifdef _DEBUG
if (GetFieldType(index) != adInteger){
m_errormessage.Format(_T("Warning: 你要存贮的字段与变量的数据类型不符; 文件: %s; 行: %d\n"), __FILE__, __LINE__);
AfxMessageBox(m_errormessage);
}
#endif
return PutCollect(index, _variant_t(long(value)));
}
BOOL CAdoRecordSet::PutCollect(LPCTSTR strFieldName, const int &value)
{
ASSERT(m_pRecordset != NULL);
#ifdef _DEBUG
if (GetFieldType(strFieldName) != adInteger){
m_errormessage.Format(_T("Warning: 你要存贮的字段与变量的数据类型不符; 文件: %s; 行: %d\n"), __FILE__, __LINE__);
AfxMessageBox(m_errormessage);
}
#endif
return PutCollect(strFieldName, _variant_t(long(value)));
}
BOOL CAdoRecordSet::PutCollect(long index, const long &value)
{
ASSERT(m_pRecordset != NULL);
#ifdef _DEBUG
if (GetFieldType(index) != adBigInt){
m_errormessage.Format(_T("Warning: 你要存贮的字段与变量的数据类型不符; 文件: %s; 行: %d\n"), __FILE__, __LINE__);
AfxMessageBox(m_errormessage);
}
#endif
return PutCollect(index, _variant_t(value));
}
BOOL CAdoRecordSet::PutCollect(LPCTSTR strFieldName, const long &value)
{
ASSERT(m_pRecordset != NULL);
#ifdef _DEBUG
if (GetFieldType(strFieldName) != adBigInt){
m_errormessage.Format(_T("Warning: 你要存贮的字段与变量的数据类型不符; 文件: %s; 行: %d\n"), __FILE__, __LINE__);
AfxMessageBox(m_errormessage);
}
#endif
return PutCollect(strFieldName, _variant_t(value));
}
BOOL CAdoRecordSet::PutCollect(long index, const DWORD &value)
{
ASSERT(m_pRecordset != NULL);
#ifdef _DEBUG
if (GetFieldType(index) != adUnsignedBigInt){
m_errormessage.Format(_T("Warning: 你要存贮的字段与变量的数据类型不符; 文件: %s; 行: %d\n"), __FILE__, __LINE__);
AfxMessageBox(m_errormessage);
}
#endif
_variant_t vt;
vt.vt = VT_UI4;
vt.ulVal = value;
return PutCollect(index, vt);
}
BOOL CAdoRecordSet::PutCollect(LPCTSTR strFieldName, const DWORD &value)
{
ASSERT(m_pRecordset != NULL);
#ifdef _DEBUG
if (GetFieldType(strFieldName) != adUnsignedBigInt){
m_errormessage.Format(_T("Warning: 你要存贮的字段与变量的数据类型不符; 文件: %s; 行: %d\n"), __FILE__, __LINE__);
AfxMessageBox(m_errormessage);
}
#endif
_variant_t vt;
vt.vt = VT_UI4;
vt.ulVal = value;
return PutCollect(strFieldName, vt);
}
BOOL CAdoRecordSet::PutCollect(long index, const float &value)
{
ASSERT(m_pRecordset != NULL);
#ifdef _DEBUG
if (GetFieldType(index) != adSingle){
m_errormessage.Format(_T("Warning: 你要存贮的字段与变量的数据类型不符; 文件: %s; 行: %d\n"), __FILE__, __LINE__);
AfxMessageBox(m_errormessage);
}
#endif
return PutCollect(index, _variant_t(value));
}
BOOL CAdoRecordSet::PutCollect(LPCTSTR strFieldName, const float &value)
{
ASSERT(m_pRecordset != NULL);
#ifdef _DEBUG
if (GetFieldType(strFieldName) != adSingle){
m_errormessage.Format(_T("Warning: 你要存贮的字段与变量的数据类型不符; 文件: %s; 行: %d\n"), __FILE__, __LINE__);
AfxMessageBox(m_errormessage);
}
#endif
return PutCollect(strFieldName, _variant_t(value));
}
BOOL CAdoRecordSet::PutCollect(long index, const double &value)
{
ASSERT(m_pRecordset != NULL);
#ifdef _DEBUG
if (GetFieldType(index) != adDouble){
m_errormessage.Format(_T("Warning: 你要存贮的字段与变量的数据类型不符; 文件: %s; 行: %d\n"), __FILE__, __LINE__);
AfxMessageBox(m_errormessage);
}
#endif
return PutCollect(index, _variant_t(value));
}
BOOL CAdoRecordSet::PutCollect(LPCTSTR strFieldName, const double &value)
{
ASSERT(m_pRecordset != NULL);
#ifdef _DEBUG
if (GetFieldType(strFieldName) != adDouble){
m_errormessage.Format(_T("Warning: 你要存贮的字段与变量的数据类型不符; 文件: %s; 行: %d\n"), __FILE__, __LINE__);
AfxMessageBox(m_errormessage);
}
#endif
return PutCollect(strFieldName, _variant_t(value));
}
BOOL CAdoRecordSet::PutCollect(long index, const COleDateTime &value)
{
ASSERT(m_pRecordset != NULL);
#ifdef _DEBUG
if ( GetFieldType(index) != adDate
&& GetFieldType(index) != adDBDate
&& GetFieldType(index) != adDBTime
&& GetFieldType(index) != adDBTimeStamp)
{
m_errormessage.Format(_T("Warning: 你要存贮的字段与变量的数据类型不符; 文件: %s; 行: %d\n"), __FILE__, __LINE__);
AfxMessageBox(m_errormessage);
}
#endif
_variant_t vt;
vt.vt = VT_DATE;
vt.date = value;
return PutCollect(index, vt);
}
BOOL CAdoRecordSet::PutCollect(LPCTSTR strFieldName, const COleDateTime &value)
{
ASSERT(m_pRecordset != NULL);
#ifdef _DEBUG
if ( GetFieldType(strFieldName) != adDate
&& GetFieldType(strFieldName) != adDBDate
&& GetFieldType(strFieldName) != adDBTime
&& GetFieldType(strFieldName) != adDBTimeStamp)
{
m_errormessage.Format(_T("Warning: 你要存贮的字段与变量的数据类型不符; 文件: %s; 行: %d\n"), __FILE__, __LINE__);
AfxMessageBox(m_errormessage);
}
#endif
_variant_t vt;
vt.vt = VT_DATE;
vt.date = value;
return PutCollect(strFieldName, vt);
}
BOOL CAdoRecordSet::PutCollect(long index, const COleCurrency &value)
{
ASSERT(m_pRecordset != NULL);
#ifdef _DEBUG
if (GetFieldType(index) != adCurrency){
m_errormessage.Format(_T("Warning: 你要存贮的字段与变量的数据类型不符; 文件: %s; 行: %d\n"), __FILE__, __LINE__);
AfxMessageBox(m_errormessage);
}
#endif
if (value.m_status == COleCurrency::invalid) return FALSE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -