打印本文 打印本文 关闭窗口 关闭窗口
ADO 方法访问数据库的封装接口(04)
作者:武汉SEO闵涛  文章来源:敏韬网  点击数2166  更新时间:2009/4/23 10:43:56  文章录入:mintao  责任编辑:mintao
; SetErrorMessage((LPCTSTR)e.Description(),__FILE__,__LINE__) ;
 }
 catch (...)
 {
  SetErrorMessage(EXCEPTION_UNKNOWN,__FILE__,__LINE__) ;
 }
 return FALSE ;
}

BOOL CDBRecordSet::IsEof(void)
{
 try
 {
  if (!m_pRecordSetImpl->isValid())
  {
   SetErrorMessage(RECORDSET_INVALIDHANDLE,__FILE__,__LINE__) ;
   return TRUE ;
  }
  BOOL bEnd = TRUE ;
  if(DBRECORDSETPtr->GetState() == adStateOpen)
  {
   bEnd = (BOOL)(DBRECORDSETPtr->GetEndOfFile());
  }
  return bEnd ;
 }
 catch (_com_error &e)
 {
  SetErrorMessage((LPCTSTR)e.Description(),__FILE__,__LINE__) ;
 }
 catch (...)
 {
  SetErrorMessage(EXCEPTION_UNKNOWN,__FILE__,__LINE__) ;
 }
 return TRUE ;
}

//是否当前位置位于第一条记录前面
BOOL CDBRecordSet::IsBof(void)
{
 try
 {
  if (!m_pRecordSetImpl->isValid())
  {
   SetErrorMessage(RECORDSET_INVALIDHANDLE,__FILE__,__LINE__) ;
   return TRUE ;
  }
  BOOL bEnd = TRUE ;
  if(DBRECORDSETPtr->GetState() == adStateOpen)
  {
   bEnd = (BOOL)(DBRECORDSETPtr->GetBOF());
  }
  return bEnd ;
 }
 catch (_com_error &e)
 {
  SetErrorMessage((LPCTSTR)e.Description(),__FILE__,__LINE__) ;
 }
 catch (...)
 {
  SetErrorMessage(EXCEPTION_UNKNOWN,__FILE__,__LINE__) ;
 }
 return TRUE ;
}

//获取记录总数
int CDBRecordSet::GetRecordCount(void)
{
 try
 {
  if (!m_pRecordSetImpl->isValid())
  {
   SetErrorMessage(RECORDSET_INVALIDHANDLE,__FILE__,__LINE__) ;
   return -1 ;
  }

  int nRecordCount = -1 ;
  if(DBRECORDSETPtr->GetState() == adStateOpen)
  {
   nRecordCount = (int)DBRECORDSETPtr->GetRecordCount() ;
  }
  return nRecordCount ;
 }
 catch (_com_error &e)
 {
  SetErrorMessage((LPCTSTR)e.Description(),__FILE__,__LINE__) ;
 }
 catch (...)
 {
  SetErrorMessage(EXCEPTION_UNKNOWN,__FILE__,__LINE__) ;
 }
 return -1 ;
}

//移动到第一个记录
BOOL CDBRecordSet::MoveFirst(void)
{
 try
 {
  if (!m_pRecordSetImpl->isValid())
  {
   SetErrorMessage(RECORDSET_INVALIDHANDLE,__FILE__,__LINE__) ;
   return FALSE ;
  }
  BOOL bMovedOK = FALSE ;
  if(DBRECORDSETPtr->GetState() == adStateOpen)
  {
   bMovedOK = SUCCEEDED(DBRECORDSETPtr->MoveFirst()) ;
  }
  return bMovedOK ;
 }
 catch (_com_error &e)
 {
  SetErrorMessage((LPCTSTR)e.Description(),__FILE__,__LINE__) ;
 }
 catch (...)
 {
  SetErrorMessage(EXCEPTION_UNKNOWN,__FILE__,__LINE__) ;
 }
 return FALSE ;
}

//移到下一个记录
BOOL CDBRecordSet::MoveNext(void)
{
 try
 {
  if (!m_pRecordSetImpl->isValid())
  {
   SetErrorMessage(RECORDSET_INVALIDHANDLE,__FILE__,__LINE__) ;
   return FALSE ;
  }
  BOOL bMovedOK = FALSE ;
  if(DBRECORDSETPtr->GetState() == adStateOpen)
  {
   bMovedOK = SUCCEEDED(DBRECORDSETPtr->MoveNext()) ;
  }
  return bMovedOK ;
 }
 catch (_com_error &e)
 {
  SetErrorMessage((LPCTSTR)e.Description(),__FILE__,__LINE__) ;
 }
 catch (...)
 {
  SetErrorMessage(EXCEPTION_UNKNOWN,__FILE__,__LINE__) ;
 }
 return FALSE ;
}

//移动到最后一个记录
BOOL CDBRecordSet::MoveLast(void)
{
 try
 {
  if (!m_pRecordSetImpl->isValid())
  {
   SetErrorMessage(RECORDSET_INVALIDHANDLE,__FILE__,__LINE__) ;
   return FALSE ;
  }
  BOOL bMovedOK = FALSE ;
  if(DBRECORDSETPtr->GetState() == adStateOpen)
  {
   bMovedOK = SUCCEEDED(DBRECORDSETPtr->MoveLast()) ;
  }
  return bMovedOK ;
 }
 catch (_com_error &e)
 {
  SetErrorMessage((LPCTSTR)e.Description(),__FILE__,__LINE__) ;
 }
 catch (...)
 {
  SetErrorMessage(EXCEPTION_UNKNOWN,__FILE__,__LINE__) ;
 }
 return FALSE ;
}

//移动到前一个记录
BOOL CDBRecordSet::MovePrevious(void)
{
 try
 {
  if (!m_pRecordSetImpl->isValid())
  {
   SetErrorMessage(RECORDSET_INVALIDHANDLE,__FILE__,__LINE__) ;
   return FALSE ;
  }
  BOOL bMovedOK = FALSE ;
  if(DBRECORDSETPtr->GetState() == adStateOpen)
  {
   bMovedOK = SUCCEEDED(DBRECORDSETPtr->MovePrevious()) ;
  }
  return bMovedOK ;
 }
 catch (_com_error &e)
 {
  SetErrorMessage((LPCTSTR)e.Description(),__FILE__,__LINE__) ;
 }
 catch (...)
 {
  SetErrorMessage(EXCEPTION_UNKNOWN,__FILE__,__LINE__) ;
 }
 return FALSE ;
}

BOOL CDBRecordSet::Move(int nOffset)
{
 try
 {
  if (!m_pRecordSetImpl->isValid())
  {
   SetErrorMessage(RECORDSET_INVALIDHANDLE,__FILE__,__LINE__) ;
   return FALSE ;
  }
  BOOL bMovedOK = FALSE ;
  if(DBRECORDSETPtr->GetState() == adStateOpen)
  {
   bMovedOK = SUCCEEDED(DBRECORDSETPtr->Move((long)nOffset)) ;
  }
  return bMovedOK ;
 }
 catch (_com_error &e)
 {
  SetErrorMessage((LPCTSTR)e.Description(),__FILE__,__LINE__) ;
 }
 catch (...)
 {
  SetErrorMessage(EXCEPTION_UNKNOWN,__FILE__,__LINE__) ;
 }
 return FALSE ;
}

int CDBRecordSet::GetFieldCount(void)
{
 try
 {
  if (!m_pRecordSetImpl->isValid())
  {
   SetErrorMessage(RECORDSET_INVALIDHANDLE,__FILE__,__LINE__) ;
   return -1 ;
  }

  int nFieldCount = -1 ;
  if(DBRECORDSETPtr->GetState() == adStateOpen)
  {
   if(DBRECORDSETPtr->GetFields() != NULL)
   {
    //记录集中包含的字段数
    nFieldCount = (int)DBRECORDSETPtr->GetFields()->GetCount() ;
   }
  }
  return nFieldCount ;
 }
 catch (_com_error &e)
 {
  SetErrorMessage((LPCTSTR)e.Description(),__FILE__,__LINE__) ;
 }
 catch (...)
 {
  SetErrorMessage(EXCEPTION_UNKNOWN,__FILE__,__LINE__) ;
 }
 return -1 ;
}

int CDBRecordSet::GetFieldOrder(LPCTSTR szFieldName)
{
 try
 {
  if (!m_pRecordSetImpl->isValid())
  {
   SetErrorMessage(RECORDSET_INVALIDHANDLE,__FILE__,__LINE__) ;
   return -1 ;
  }

  int nFieldOrder = -1 ;
  if(DBRECORDSETPtr->GetState() == adStateOpen)
  {
   if(DBRECORDSETPtr->GetFields() != NULL)
   {
    //记录集中包含的字段数
    long nFieldCount = (int)DBRECORDSETPtr->GetFields()->GetCount() ;
    for(long nIndex = 0L; nIndex < nFieldCount; nIndex++)
    {
     if(DBRECORDSETPtr->GetFields()->Item[nIndex]->Name == _bstr_t(szFieldName))
     {
      nFieldOrder = nIndex ;
      break ; //找到该字段
     }
    }
   }
  }
  return nFieldOrder ;
 }
 catch (_com_error &e)
 {
  SetErrorMessage((LPCTSTR)e.Description(),__FILE__,__LINE__) ;
 }
 catch (...)
 {
  SetErrorMessage(EXCEPTION_UNKNOWN,__FILE__,__LINE__) ;
 }
 return -1 ;
}

LPCTSTR CDBRecordSet::GetFieldName(int nFieldOrder)
{
 try
 {
  m_strTempFieldName.Empty() ;
  if (!m_pRecordSetImpl->isValid())
  {
   SetErrorMessage(RECORDSET_INVALIDHANDLE,__FILE__,__LINE__) ;
   return (LPCTSTR)m_strTempFieldName;
  }

  if(DBRECORDSETPtr->GetState() == adStateOpen)
  {
   if(DBRECORDSETPtr->GetFields() != NULL)
   {
    //记录集中包含的字段数
    long nFieldCount = (int)DBRECORDSETPtr->GetFields()->GetCount() ;
    if(nFieldCount > 0)
    {
     if((nFieldOrder >= 0) &

上一页  [1] [2] [3]  下一页

打印本文 打印本文 关闭窗口 关闭窗口