📄 adorecordset.cpp
字号:
对象的 Resync、UpdateBatch 或 CancelBatch 方法, 或者设置 Recordset 对象
的 Filter 属性为书签数组. 使用该属性, 可检查指定记录为何失败并将问题解
决.
==========================================================================*/
long CAdoRecordSet::GetStatus()
{
ASSERT(m_pRecordset != NULL);
try
{
return m_pRecordset->GetStatus();
}
catch (_com_error e)
{
TRACE(_T("Warning: GetStatus 方法发生异常. 错误信息: %s; 文件: %s; 行: %d\n"), e.ErrorMessage(), __FILE__, __LINE__);
return -1;
}
return -1;
}
/*========================================================================
Name: 获取当前记录集中记录数目
==========================================================================*/
long CAdoRecordSet::GetRecordCount()
{
ASSERT(m_pRecordset != NULL);
try
{
long count = m_pRecordset->GetRecordCount();
// 如果ado不支持此属性,则手工计算记录数目 --------
if (count < 0)
{
long pos = GetAbsolutePosition();
MoveFirst();
count = 0;
while (!IsEOF())
{
count++;
MoveNext();
}
SetAbsolutePosition(pos);
}
return count;
}
catch (_com_error e)
{
TRACE(_T("Warning: GetRecordCount 方法发生异常. 错误信息: %s; 文件: %s; 行: %d\n"), e.ErrorMessage(), __FILE__, __LINE__);
return -1;
}
}
/*========================================================================
Name: 获取当前记录集中字段数目
==========================================================================*/
long CAdoRecordSet::GetFieldsCount()
{
ASSERT(m_pRecordset != NULL);
try
{
return GetFields()->Count;
}
catch(_com_error e)
{
TRACE(_T("Warning: GetFieldsCount 方法发生异常. 错误信息: %s; 文件: %s; 行: %d\n"), e.ErrorMessage(), __FILE__, __LINE__);
return -1;
}
}
/*========================================================================
Name: 指示通过查询返回 Recordset 的记录的最大数目.
==========================================================================*/
long CAdoRecordSet::GetMaxRecordCount()
{
ASSERT(m_pRecordset != NULL);
try
{
return m_pRecordset->GetMaxRecords();
}
catch (_com_error e)
{
TRACE(_T("Warning: GetMaxRecordCount 方法发生异常. 错误信息: %s; 文件: %s; 行: %d\n"), e.ErrorMessage(), __FILE__, __LINE__);
return -1;
}
}
BOOL CAdoRecordSet::SetMaxRecordCount(long count)
{
ASSERT(m_pRecordset != NULL);
try
{
m_pRecordset->PutMaxRecords(count);
return TRUE;
}
catch (_com_error e)
{
TRACE(_T("Warning: GetMaxRecordCount 方法发生异常. 错误信息: %s; 文件: %s; 行: %d\n"), e.ErrorMessage(), __FILE__, __LINE__);
return FALSE;
}
}
/*========================================================================
Name: 指针是否在在记录集头
==========================================================================*/
BOOL CAdoRecordSet::IsBOF()
{
ASSERT(m_pRecordset != NULL);
try
{
return m_pRecordset->adoBOF;
}
catch(_com_error e)
{
TRACE(_T("Warning: IsBOF 方法发生异常. 错误信息: %s; 文件: %s; 行: %d\n"), e.ErrorMessage(), __FILE__, __LINE__);
return FALSE;
}
return FALSE;
}
/*========================================================================
Name: 指针是否在在记录集尾
==========================================================================*/
BOOL CAdoRecordSet::IsEOF()
{
ASSERT(m_pRecordset != NULL);
try
{
return m_pRecordset->adoEOF;
}
catch (_com_error e)
{
TRACE(_T("Warning: IsEOF 方法发生异常. 错误信息: %s; 文件: %s; 行: %d\n"), e.ErrorMessage(), __FILE__, __LINE__);
return FALSE;
}
}
EditModeEnum CAdoRecordSet::GetEditMode()
{
ASSERT(m_pRecordset != NULL);
try
{
if (m_pRecordset != NULL)
{
return m_pRecordset->GetEditMode();
}
}
catch (_com_error e)
{
TRACE(_T("Warning: GetEditMode 方法发生异常. 错误信息: %s; 文件: %s; 行: %d\n"), e.ErrorMessage(), __FILE__, __LINE__);
return adEditNone;
}
return adEditNone;
}
long CAdoRecordSet::GetPageCount()
{
ASSERT(m_pRecordset != NULL);
try
{
return m_pRecordset->GetPageCount();
}
catch (_com_error &e)
{
TRACE(_T("Warning: GetPageCount 方法发生异常. 错误信息: %s; 文件: %s; 行: %d\n"), e.ErrorMessage(), __FILE__, __LINE__);
return -1;
}
}
BOOL CAdoRecordSet::SetCacheSize(const long &lCacheSize)
{
ASSERT(m_pRecordset != NULL);
try
{
if (m_pRecordset != NULL && !(GetState() & adStateExecuting))
{
m_pRecordset->PutCacheSize(lCacheSize);
}
}
catch (const _com_error& e)
{
TRACE(_T("Warning: SetCacheSize方法发生异常. 错误信息: %s; 文件: %s; 行: %d\n"), e.ErrorMessage(), __FILE__, __LINE__);
return FALSE;
}
return TRUE;
}
long CAdoRecordSet::GetPageSize()
{
ASSERT(m_pRecordset != NULL);
try
{
return m_pRecordset->GetPageSize();
}
catch (_com_error &e)
{
TRACE(_T("Warning: GetPageCount 方法发生异常. 错误信息: %s; 文件: %s; 行: %d\n"), e.ErrorMessage(), __FILE__, __LINE__);
return -1;
}
}
/*========================================================================
name: 指定当前记录所在的页.
----------------------------------------------------------
returns: 置或返回从 1 到 Recordset 对象 (PageCount) 所含页数的长整型
值,或者返回以下常量.
[常量] [说明]
---------------------------------
adPosUnknown Recordset 为空,当前位置未知,或者提供者不支持 AbsolutePage 属性.
adPosBOF 当前记录指针位于 BOF(即 BOF 属性为 True).
adPosEOF 当前记录指针位于 EOF(即 EOF 属性为 True).
==========================================================================*/
BOOL CAdoRecordSet::SetAbsolutePage(int nPage)
{
ASSERT(m_pRecordset != NULL);
try
{
m_pRecordset->PutAbsolutePage((enum PositionEnum)nPage);
return TRUE;
}
catch(_com_error &e)
{
TRACE(_T("Warning: SetAbsolutePage 方法发生异常. 错误信息: %s; 文件: %s; 行: %d\n"), e.ErrorMessage(), __FILE__, __LINE__);
return FALSE;
}
}
long CAdoRecordSet::GetAbsolutePage()
{
ASSERT(m_pRecordset != NULL);
try
{
return m_pRecordset->GetAbsolutePage();
}
catch(_com_error &e)
{
TRACE(_T("Warning: GetAbsolutePage 方法发生异常. 错误信息: %s; 文件: %s; 行: %d\n"), e.ErrorMessage(), __FILE__, __LINE__);
return -1;
}
}
/*========================================================================
name: 指定 Recordset 对象当前记录的序号位置.
----------------------------------------------------------
returns: 设置或返回从 1 到 Recordset 对象 (PageCount) 所含页数的长整
型值,或者返回以下常量.
[常量] [说明]
---------------------------------
adPosUnknown Recordset 为空,当前位置未知,或者提供者不支持 AbsolutePage 属性.
adPosBOF 当前记录指针位于 BOF(即 BOF 属性为 True).
adPosEOF 当前记录指针位于 EOF(即 EOF 属性为 True).
----------------------------------------------------------
Remarks: 使用 AbsolutePosition 属性可根据其在 Recordset 中的序号
位置移动到记录,或确定当前记录的序号位置. 提供者必须支持该属性的相应功
能才能使用该属性.
同 AbsolutePage 属性一样,AbsolutePosition 从 1 开始,并在当前记录
为 Recordset 中的第一个记录时等于 1. 从 RecordCount 属性可获得 Recordset
对象的总记录数.
设置 AbsolutePosition 属性时,即使该属性指向位于当前缓存中的记录,
ADO 也将使用以指定的记录开始的新记录组重新加载缓存. CacheSize 属性决定
该记录组的大小.
注意 不能将 AbsolutePosition 属性作为替代的记录编号使用. 删除前面
的记录时,给定记录的当前位置将发生改变. 如果 Recordset 对象被重新查询或
重新打开,则无法保证给定记录有相同的 AbsolutePosition. 书签仍然是保持和
返回给定位置的推荐方式,并且在所有类型的 Recordset 对象的定位时是唯一的
方式.
==========================================================================*/
BOOL CAdoRecordSet::SetAbsolutePosition(int nPosition)
{
ASSERT(m_pRecordset != NULL);
try
{
m_pRecordset->PutAbsolutePosition((enum PositionEnum)nPosition);
return TRUE;
}
catch(_com_error &e)
{
TRACE(_T("Warning: SetAbsolutePosition 方法发生异常. 错误信息: %s; 文件: %s; 行: %d\n"), e.ErrorMessage(), __FILE__, __LINE__);
return FALSE;
}
}
long CAdoRecordSet::GetAbsolutePosition()
{
ASSERT(m_pRecordset != NULL);
try
{
return m_pRecordset->GetAbsolutePosition();
}
catch(_com_error &e)
{
TRACE(_T("Warning: GetAbsolutePosition 方法发生异常. 错误信息: %s; 文件: %s; 行: %d\n"), e.ErrorMessage(), __FILE__, __LINE__);
return -1;
}
}
BOOL CAdoRecordSet::SetCursorLocation(CursorLocationEnum CursorLocation)
{
ASSERT(m_pRecordset != NULL);
try
{
m_pRecordset->PutCursorLocation(CursorLocation);
return TRUE;
}
catch (_com_error e)
{
TRACE(_T("Warning: PutCursorLocation 方法发生异常. 错误信息: %s; 文件: %s; 行: %d\n"), e.ErrorMessage(), __FILE__, __LINE__);
return FALSE;
}
}
CursorLocationEnum CAdoRecordSet::GetCursorLocation()
{
ASSERT(m_pRecordset != NULL);
try
{
return m_pRecordset->GetCursorLocation();
}
catch (_com_error e)
{
TRACE(_T("Warning: GetCursorLocation 方法发生异常. 错误信息: %s; 文件: %s; 行: %d\n"), e.ErrorMessage(), __FILE__, __LINE__);
return adUseNone;
}
}
BOOL CAdoRecordSet::SetCursorType(CursorTypeEnum CursorType)
{
ASSERT(m_pRecordset != NULL);
try
{
m_pRecordset->PutCursorType(CursorType);
return TRUE;
}
catch (_com_error e)
{
TRACE(_T("Warning: SetCursorType 方法发生异常. 错误信息: %s; 文件: %s; 行: %d\n"), e.ErrorMessage(), __FILE__, __LINE__);
return FALSE;
}
}
CursorTypeEnum CAdoRecordSet::GetCursorType()
{
ASSERT(m_pRecordset != NULL);
try
{
return m_pRecordset->GetCursorType();
}
catch (_com_error e)
{
TRACE(_T("Warning: GetCursorType 方法发生异常. 错误信息: %s; 文件: %s; 行: %d\n"), e.ErrorMessage(), __FILE__, __LINE__);
return adOpenUnspecified;
}
}
/*========================================================================
Remarks: Recordset 对象包括 Field 对象组成的 Fields 集合. 每个Field
对象对应 Recordset 集中的一列.
==========================================================================*/
FieldsPtr CAdoRecordSet::GetFields()
{
ASSERT(m_pRecordset != NULL);
try
{
return m_pRecordset->GetFields();
}
catch (_com_error e)
{
TRACE(_T("Warning: GetFields 方法发生异常. 错误信息: %s; 文件: %s; 行: %d\n"), e.ErrorMessage(), __FILE__, __LINE__);
return NULL;
}
return NULL;
}
/*========================================================================
Remarks: 取得指定列字段的字段名.
==========================================================================*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -