本文整理汇总了C++中_RecordsetPtr类的典型用法代码示例。如果您正苦于以下问题:C++ _RecordsetPtr类的具体用法?C++ _RecordsetPtr怎么用?C++ _RecordsetPtr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了_RecordsetPtr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OnShowGrid
void CDlg::OnShowGrid(CString strSql,_RecordsetPtr& rs,_CommandPtr& Cmd,CDatagrid1& Grd,void (*pFGrd)(CDatagrid1&,_RecordsetPtr&))
{
if(!strSql.IsEmpty()) {
Cmd->CommandText = (_bstr_t)strSql;
try {
Grd.putref_DataSource(NULL);
if(rs->State==adStateOpen) rs->Close();
rs->Open(m_vNULL,m_vNULL,adOpenDynamic,adLockOptimistic,adCmdText);
m_Flg = false;
// m_Flg = true;
//AfxMessageBox(L"Before OnShow Grd.putref_DataSource((LPUNKNOWN)rs)");
Grd.putref_DataSource((LPUNKNOWN)rs);
//AfxMessageBox(L"After OnShow Grd.putref_DataSource((LPUNKNOWN)rs)");
// m_Flg = false;
/*----*/// m_Flg = true;
m_CurCol = Grd.get_Col();
// s.Format("%i",m_CurCol);
// AfxMessageBox(s);
if(m_CurCol==-1 || m_CurCol==0 ) {
m_CurCol = 1;
}
m_iCurType = GetTypeCol(rs,m_CurCol);
pFGrd(Grd,rs);
}
catch(_com_error& e) {
Grd.putref_DataSource(NULL);
AfxMessageBox(e.ErrorMessage());
}
}
}
示例2: GetRecordCount
UINT CBADO::GetRecordCount( _RecordsetPtr pRecordset )
{
int nCount = 0;
try
{
if(pRecordset->EndOfFile)
{
Sleep(1);
return 0;
}
pRecordset->MoveFirst();
}
catch(...)
{
return 0;
}
if (pRecordset->FirstOfFile)
return 0;
while(!pRecordset->EndOfFile)
{
pRecordset->MoveNext();
nCount = nCount + 1;
}
pRecordset->MoveFirst();
return nCount;
}
示例3: RecNo
///////////////////////////////////////////////
//
//返回当前记录集的游标位置
//
//IRecordset[in] 记录集智能指针
//
//函数成功返回当前记录集的游标位置,否则返回-1
//
long CFoxBase::RecNo(_RecordsetPtr IRecordset)
{
long pos=0;
long i;
if(IRecordset==NULL)
return -1;
if(IRecordset->adoEOF && IRecordset->BOF)
return -1;
while(!IRecordset->GetBOF())
{
pos++;
IRecordset->MovePrevious();
}
i=pos;
i--;
IRecordset->MoveFirst();
while(i>0)
{
i--;
IRecordset->MoveNext();
}
return pos;
}
示例4: GetDataStr
CString CADODB::GetDataStr(_RecordsetPtr pRecordset)
{
if (NULL == pRecordset) return _T("");
CString strData;
int nFieldsCount = pRecordset->Fields->GetCount(); // 字段数;
for (int i = 0; i < nFieldsCount; i++)
{
char *pszName = _com_util::ConvertBSTRToString(pRecordset->Fields->GetItem((long)i)->GetName()); // 字段名
strData += pszName;
strData += _T("\t");
delete[] pszName;
}
strData += _T("\n");
while (!pRecordset->EndOfFile) //遍历所有记录
{
for (int i = 0; i < nFieldsCount; i++)
{
strData += pRecordset->GetCollect((long)i);
strData += _T("\t");
}
strData += _T("\n");
pRecordset->MoveNext();
}
return strData;
}
示例5: switch
void CDlg::InitDataGrid1(CDatagrid1& Grd,_RecordsetPtr& rs)
{
CColumns GrdClms;
CString strCap,strRec;
CString s;
long num,numRec;
short i;
float wdth;
strCap.LoadString(IDS_STRING9013);
numRec = 0;
GrdClms.AttachDispatch(Grd.get_Columns());
if(rs->State==adStateOpen) {
num = rs->GetadoFields()->GetCount();
numRec = rs->GetRecordCount();
strRec.Format(_T(" %i"),numRec);
strCap +=strRec;
Grd.put_Caption(strCap);
for (i=0; i<num; i++) {
switch(i) {
case 0:
GrdClms.GetItem((COleVariant) i).SetVisible(FALSE);
break;
case 1:
wdth = 75;
GrdClms.GetItem((COleVariant) i).SetWidth(wdth);
break;
case 2:
wdth = 190;
GrdClms.GetItem((COleVariant) i).SetWidth(wdth);
break;
case 3:
wdth = 48;
GrdClms.GetItem((COleVariant) i).SetWidth(wdth);
break;
case 4:
wdth = 185;
GrdClms.GetItem((COleVariant) i).SetWidth(wdth);
break;
case 5:
wdth = 100;
GrdClms.GetItem((COleVariant) i).SetWidth(wdth);
break;
default:
GrdClms.GetItem((COleVariant) i).SetVisible(FALSE);
break;
}
}
}
else {
strRec.Format(_T(" %i"),numRec);
strCap +=strRec;
Grd.put_Caption(strCap);
}
}
示例6: create_rs
void HiDBOracle::create_rs(const char* name, const char* sql, _RecordsetPtr& rs)
{
::CoInitialize(NULL);
HRESULT hr = rs.CreateInstance(__uuidof(Recordset));
if (FAILED(hr))
{
_com_error e(hr);
on_excetion("HiDBOracle::ExecuteScalar", sql, e);
}
rs->PutCursorLocation(adUseClient);
}
示例7: ADORecordsetOpen
int CCommDBOper::ADORecordsetOpen(_ConnectionPtr &pCon,_RecordsetPtr pRs,CString strOpenSql,CString strDcrOpen,int iWarn)
{
//函数说明:执行指定记录集对象指定SQL操作
//pCon 数据库连接对象
//pRs 当前操作用记录集对象
//strOpenSql 要执行的SQL命令
//strDcrOpen是对要使用SQL命令的描述
_variant_t tempStrSql;
tempStrSql = strOpenSql;
if (pRs == NULL)
{
pRs.CreateInstance(__uuidof(Recordset));
pRs->CursorLocation = adUseClient;
}
ADOCloseRecordset(pRs,0);
while (true)
{
try
{
//有错 pRs->Open(tempStrSql,_variant_t(pCon),adOpenDynamic,adLockOptimistic,adCmdText);
pRs->Open(tempStrSql,(IDispatch *)pCon,adOpenDynamic,adLockOptimistic,adCmdText);
break;
}
catch (_com_error &e)
{
CString strMsg;
strMsg.Format("%s:%d %s", __FILE__, __LINE__, (LPSTR)e.Description());
AfxMessageBox(strMsg);
}
try
{
//如果第一次打开失败,看能否以只读方式打开
pRs->Open(tempStrSql,(IDispatch *)pCon,adOpenDynamic,adLockReadOnly,adCmdText);
return 2;
}
catch (_com_error &e)
{
CString strMsg;
strMsg.Format("%s:%d %s", __FILE__, __LINE__, (LPSTR)e.Description());
AfxMessageBox(strMsg);
CString errormessage;
errormessage.Format("功能说明: %s\r\n记录集对象执行下列SQL命令\r\n%s\r\n失败! 错误信息:%s",strDcrOpen,strOpenSql,e.ErrorMessage());
WarnMessage(errormessage,iWarn);//显示错误信息
return RET_FAILED;
}
}
return RET_OK;
}
示例8: ReplAll
///////////////////////////////////////////////////////////
//
//替换记录集中选中字段所有的值
//
//IRecordset[in] 记录集智能指针
//FieldsName[in] 字段名
//Value[in] 输入替换FieldsName字段的值
//
//函数成功返回TRUE,否则返回FALSE
//当函数成功返回时,当前游标指针指向记录集最后一个记录的后面
//
BOOL CFoxBase::ReplAll(_RecordsetPtr IRecordset, _variant_t FieldsName, _variant_t Value)
{
if(IRecordset==NULL)
return FALSE;
IRecordset->MoveFirst();
while(!IRecordset->adoEOF)
{
IRecordset->PutCollect(FieldsName,Value);
IRecordset->Update();
IRecordset->MoveNext();
}
return TRUE;
}
示例9: PutTbValue
/////////////////////////////////////////////////////////////////////////////////////////
//
// 在记录集中当前游标位置设置指定的字段的值
//
// IRecordset[in] 记录集智能指针
// FieldsName[in] 字段名
// Value[in] 新的值
//
// 如果有异常将调用ExceptionInfo函数
//
void CFoxBase::PutTbValue(_RecordsetPtr IRecordset, _variant_t FieldsName, double Value)
{
if(IRecordset==NULL)
return;
try
{
IRecordset->PutCollect(FieldsName,_variant_t(Value));
IRecordset->Update();
}
catch(_com_error /*&e*/)
{
// ExceptionInfo(e);
throw;
}
}
示例10: GetRecordset
_RecordsetPtr& GetRecordset(_bstr_t SQL)
{
m_pRecordset=NULL;
try{
if(m_pConnection==NULL)
//连接
Connect();
m_pRecordset.CreateInstance(__uuidof(Recordset));
m_pRecordset->Open((_bstr_t)SQL, m_pConnection.GetInterfacePtr(), adOpenDynamic, adLockOptimistic, adCmdText);
}
catch(_com_error e){
cout<<e.Description()<<endl;
m_pRecordset=NULL;
return m_pRecordset;
}
return m_pRecordset;
}
示例11: switch
__int64
ADOConnection::_GetIdentityFromRS(_RecordsetPtr pRS) const
{
try
{
if (pRS->GetRecordCount() == 0)
return 0;
_variant_t vaField;
FieldsPtr pFields;
FieldPtr pField;
HRESULT hr;
hr = pRS->get_Fields( &pFields );
vaField = "IDENT";
pFields->get_Item( vaField, &pField );
vaField.Clear();
if (pField)
{
pField->get_Value(&vaField);
switch (vaField.vt)
{
case VT_NULL:
return 0;
case VT_I4:
return vaField.intVal;
default:
if (vaField.decVal.sign == DECIMAL_NEG)
return -vaField.cyVal.int64;
else
return vaField.cyVal.int64;
}
}
return 0;
}
catch (...)
{
ErrorManager::Instance()->ReportError(ErrorManager::High, 5030, "ADOConnection::_GetIdentityFromRS", "Error while determening @@IDENTITY");
}
return 0;
}
示例12: UnitsToUeUnits
//单位换算
//SourceUnits 被转换的单位
//UeUnits 转换后的单位
//返回单位换算因子
//dOffset 偏移值
double CAESARIIToPHS::UnitsToUeUnits(_RecordsetPtr rsData,CString SourceUnits,CString UeUnits,double &dOffset)
{
double x;//单位换算因子
CString strSQL;
_RecordsetPtr pRs;
_ConnectionPtr pCon;
pCon.CreateInstance(__uuidof(Connection));
pRs.CreateInstance(__uuidof(Recordset));
strSQL="select * from UnitsToUeUnits ";//删除了pfg20050629where Units='"+SourceUnits+"' and UeUnits='"+UeUnits+"'
try
{
pCon=rsData->GetActiveConnection();
pRs->Open(_variant_t(strSQL),(IDispatch*)pCon,adOpenStatic,adLockOptimistic,adCmdText);
pRs->Filter=_variant_t("Units='"+SourceUnits+"' and UeUnits='"+UeUnits+"'");//pfg20050629
if(pRs->GetRecordCount()>0)
{
x=vtof(pRs->GetCollect(_T("value")));
dOffset=vtof(pRs->GetCollect(_T("offset")));//pfg20050701
return x;
}
else if(pRs->GetRecordCount()==0)
{
//pfg20050629弹出增加单位转换关系对话框(statr)
CUnitsTransformDlg dlg;
pRs->Filter="";
dlg.m_pRsUnits=pRs;
dlg.m_strDestinationUnits=UeUnits;
dlg.m_strSourceUnits=SourceUnits;
if((dlg.DoModal())==IDOK)
{
pRs=dlg.m_pRsUnits;//pfg20050630
pRs->Filter=_variant_t("Units='"+SourceUnits+"' and UeUnits='"+UeUnits+"'");//pfg20050629
if(pRs->GetRecordCount()>0)
{
dOffset=vtof(pRs->GetCollect("Offset"));//pfg20050701
x=vtof(pRs->GetCollect(_T("value")));
return x;
}
else
return 1.0;
}
else
{
m_IsCaesarError=TRUE;//增加了一个条件pfg20050627
}
//pfg20050629弹出增加单位转换关系对话框(end)
}
}
catch(_com_error &e)
{
if(AfxMessageBox("错误:当前单位不能转换,请更换单位后重试(仔细阅读使用说明)!",MB_YESNO)==IDYES)
{
m_IsCaesarError=TRUE;//增加了一个条件pfg20050627
}
}
return 1.0;
}
示例13: OpenQuery
DWORD CNHSQLServerDBO::OpenQuery(const _ConnectionPtr &pConnection, _RecordsetPtr &pRecordset, const wchar_t *const pwchSQL)
{
assert(NULL != pConnection);
assert(NULL != pwchSQL);
DWORD dwReturn(0x00);
try
{
pRecordset.CreateInstance(L"ADODB.Recordset");
pRecordset->Open((_bstr_t)pwchSQL,
_variant_t((IDispatch*)pConnection, true),
adOpenStatic,
adLockOptimistic,
adCmdText);
}
catch (_com_error &e)
{
//#ifdef _DEBUG
const int nErrMsgLength(MAX_PATH);
wchar_t *pwchErrMsg = new wchar_t[nErrMsgLength]();
_snwprintf_s(pwchErrMsg, nErrMsgLength, _TRUNCATE, L"CNHSQLServerDBO::OpenQuery发生错误(执行%s)。", pwchSQL);
// 输出错误信息到输出窗口
OutputDebugStringW(L"\t");
OutputDebugStringW(pwchErrMsg);
OutputDebugStringW(L"\n");
// 输出错误信息到日志文件
if (0 != wcscmp(m_wchLogFilePath, L""))
{
// 当日志文件路径不为空时,写日志
CNHLogAPI::WriteLogEx(m_wchLogFilePath, LOG_ERR, L"NHSQLServerDBO", pwchErrMsg);
}
if (NULL != pwchErrMsg)
{
delete[] pwchErrMsg;
pwchErrMsg = NULL;
}
OutputDBErrMsg(e);
//#endif
dwReturn = 0x01;
}
return dwReturn;
}
示例14: ReplNext
///////////////////////////////////////////////////////////
//
//替换从记录集中选中字段指定条记录的值(相当于FOXPRO中 Replace Next)
//
//IRecordset[in] 记录集智能指针
//FieldsName[in] 字段名
//Value[in] 输入替换FieldsName字段的值
//num[in] 需替换的记录数
//
//函数成功返回TRUE,否则返回FALSE
//函数从当前游标位置开始替换
//当函数成功返回时,当前游标指针指向最后修改的记录集上
//当需替换的记录数超过最后一条记录时,游标指向最后一条记录的后面
//
BOOL CFoxBase::ReplNext(_RecordsetPtr IRecordset, _variant_t FieldsName, _variant_t Value, int num)
{
if(IRecordset==NULL || num<=0)
return FALSE;
while(!IRecordset->adoEOF)
{
IRecordset->PutCollect(FieldsName,Value);
IRecordset->Update();
num--;
if(num<=0)
break;
IRecordset->MoveNext();
}
return TRUE;
}
示例15: QuerySQL
LRESULT DBConnect::QuerySQL(LPCSTR bstrSQL, _RecordsetPtr& pRecordset, CursorTypeEnum cursorType, LockTypeEnum lockType)
{
if (!m_bDBOpen||m_pAdoConn->GetState()!=ADODB::adStateOpen)
{
return -1;
}
try
{
pRecordset.CreateInstance(__uuidof(Recordset));
pRecordset->Open((_bstr_t)bstrSQL, m_pAdoConn.GetInterfacePtr(), cursorType /*adOpenStatic*/ /*adOpenDynamic*/, lockType/*adLockOptimistic*/, adCmdText);
}
catch(_com_error e)
{
MessageBox(NULL,e.Description(),_T("提示") ,1);
throw e;
}
return 0;
}