本文整理汇总了C++中_RecordsetPtr::Open方法的典型用法代码示例。如果您正苦于以下问题:C++ _RecordsetPtr::Open方法的具体用法?C++ _RecordsetPtr::Open怎么用?C++ _RecordsetPtr::Open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类_RecordsetPtr
的用法示例。
在下文中一共展示了_RecordsetPtr::Open方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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;
Grd.putref_DataSource((LPUNKNOWN)rs);
/* m_CurCol = Grd.get_Col();
if(m_CurCol==-1 || m_CurCol==EmpCol ){
m_CurCol = DefCol;
}
m_iCurType = GetTypeCol(rs,m_CurCol);
m_EditTBCh.SetTypeCol(m_iCurType);
*/
pFGrd(Grd,rs);
}
catch(_com_error& e){
Grd.putref_DataSource(NULL);
AfxMessageBox(e.ErrorMessage());
}
}
}
示例3: 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;
}
示例4: 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;
}
示例5: 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;
}
示例6: GetRecordSet
//Get record of database
bool DataConnection::GetRecordSet(_RecordsetPtr &m_pRecordset , _bstr_t bstrSQL)
//第一个参数是引用类型,也就是传出参数,可看做函数的返回值,第二个参数是SQL语句,是输入。
{
try
{
if(m_pConnection==NULL) //初始化连接
OnInitADOConn();
m_pRecordset.CreateInstance(__uuidof(Recordset));
m_pConnection->CursorLocation = adUseClient;
m_pRecordset->Open(bstrSQL,m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
return true;
}
catch(_com_error e) //失败
{
MessageBox(NULL,e.Description(),"提示",MB_ICONINFORMATION | MB_OK);
return false;
}
}
示例7:
// 打开记录集
_RecordsetPtr& ADOConn::GetRecordSet(_bstr_t bstrSQL)
{
//TODO: insert return statement here
try
{
if (m_pConnection==NULL)
{
OnInitADOConn();
}
//创建记录对象
m_pRecordset.CreateInstance(__uuidof(Recordset));
//取得表中记录
m_pRecordset->Open(bstrSQL,m_pConnection.GetInterfacePtr(),adOpenDynamic,
adLockOptimistic,adCmdText);
}
catch (_com_error e)
{
e.Description();
}
return m_pRecordset;
}
示例8: RunSP_ReturnRS
void CADOUtil::RunSP_ReturnRS(_bstr_t SP_Name, _RecordsetPtr& out_pRs, CParamArray *ParamArray)
{
if(!CheckCurrentProcess())
throw ERR_NEW_PROCESS_DETECTED;
_ConnectionPtr pConn = NULL;
_ParameterPtr pPrm = NULL;
_ParameterPtr pprm = NULL;
ErrorPtr pErr = NULL;
_CommandPtr pComm = NULL;
CParam* pr = NULL;
LONG ErrSQLState = 0;
LONG count = 0;
LONG ErrorCode = 0;
_variant_t vIndex;
_bstr_t bsEmpty;
//********************************************************************
//Connectin to Pool
try
{
_bstr_t bstrConnString(szConnectionString);
pConn.CreateInstance(__uuidof(Connection));
if(pConn == NULL)
{
throw(ErrorCode = ERR_UNABLE_CREATE_CONN);
}
pConn->ConnectionTimeout = 7;
pConn->Open(bstrConnString, L"", L"", adConnectUnspecified);
}
catch(...)
{
Beep(2000, 100);
//m_ExternalLink.Add2Log(WL_ERROR_LEVEL1,"Unable set connection to SQL Error = Unknown");
ErrorCode = ERR_UNABLE_CREATE_CONN;
}
if(ErrorCode)
throw ErrorCode;
//*******************************************************************
//Execut command
try
{
pComm.CreateInstance(__uuidof(Command));
if(pComm == NULL)
{
throw(ErrorCode = ERR_UNABLE_CREATE_COMM);
}
out_pRs.CreateInstance(__uuidof(Recordset));
if(out_pRs == NULL)
{
throw(ErrorCode = ERR_UNABLE_CREATE_RECSET);
}
pComm->ActiveConnection = pConn;
pComm->CommandText = SP_Name;
pComm->CommandType = adCmdStoredProc;
if(ParamArray != NULL)
{
DWORD Count = ParamArray->GetSize();
for (DWORD i=0; i < Count; i++)
{
pr = (*ParamArray)[i];
pprm = pComm->CreateParameter(bsEmpty, pr->Type, pr->Direction, pr->Size, pr->Value);
pComm->Parameters->Append(pprm);
}
}
out_pRs->CursorLocation = adUseClient;
out_pRs->Open(_variant_t((IDispatch *)pComm, true), vtMissing, adOpenForwardOnly, adLockReadOnly, NULL);
out_pRs->PutRefActiveConnection(NULL);
pConn->Close();
return;
}
//Handle Execut error
catch(_com_error)
{
try
{
count = pConn->Errors->Count;
if(count)
{
vIndex = _variant_t((LONG)0);
pErr = pConn->Errors->GetItem(vIndex);
ErrSQLState = atol((LPCSTR)pErr->SQLState);
/*
//m_ExternalLink.Add2Log(WL_ERROR_LEVEL3,
"SQL (RS) Error %d [Error #%d Description \"%s\" (Source: %s)"
"(SQL State: %s)](NativeError: %s)",
e.Error(),
pErr->Number,
(LPCSTR)pErr->Description,
(LPCSTR)pErr->Source,
(LPCSTR)pErr->SQLState,
(LPCSTR)pErr->NativeError);*/
}
pConn->Close();
if (pComm->ActiveConnection != NULL)
//.........这里部分代码省略.........
示例9: SaveSlideData
void CBacilusDetectDoc::SaveSlideData()
{
CString sql;
m_pRs->raw_Close();
sql.Format(_T("select *from BacilusDetect.dbo.PatientPerInfo where SlideID = '%s'"),m_SlideBoxData.SlideInfo.strSlideID);
m_pRs->Open((_variant_t)sql,m_pCon.GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);
if(m_pRs->adoEOF)//如果之前没有SlideID信息则
{
try
{
m_pRs->raw_Close();
//病人个人信息表
m_pRs->Open("SELECT * FROM BacilusDetect.dbo.PatientPerInfo",_variant_t((IDispatch*)m_pCon),adOpenStatic,adLockOptimistic,adCmdText);
m_pRs->AddNew();//添加一条新记录
m_pRs->Fields->GetItem(_variant_t("Name"))->Value=(_bstr_t)m_SlideBoxData.SlideInfo.strName;
m_pRs->Fields->GetItem(_variant_t("PatientID"))->Value=(_bstr_t)m_SlideBoxData.SlideInfo.strPatientID;
m_pRs->Fields->GetItem(_variant_t("Department"))->Value=(_bstr_t)m_SlideBoxData.SlideInfo.strDepartment;
m_pRs->Fields->GetItem(_variant_t("BedID"))->Value=(_bstr_t)m_SlideBoxData.SlideInfo.strBedID;
m_pRs->Fields->GetItem(_variant_t("Gender"))->Value=(_bstr_t)m_SlideBoxData.SlideInfo.nGender;
m_pRs->Fields->GetItem(_variant_t("Year"))->Value=(_bstr_t)m_SlideBoxData.SlideInfo.nYear;
m_pRs->Fields->GetItem(_variant_t("Occupation"))->Value=(_bstr_t)m_SlideBoxData.SlideInfo.strOccupation;
m_pRs->Fields->GetItem(_variant_t("Telephone"))->Value=(_bstr_t)m_SlideBoxData.SlideInfo.strTelephone;
m_pRs->Fields->GetItem(_variant_t("Address"))->Value=(_bstr_t)m_SlideBoxData.SlideInfo.strAddress;
m_pRs->Fields->GetItem(_variant_t("SlideID"))->Value=(_bstr_t)m_SlideBoxData.SlideInfo.strSlideID;
m_pRs->Update();
AfxMessageBox(_T("病人个人信息表保存成功!"));
}
catch(...)
{
AfxMessageBox(_T("病人个人信息表保存失败!"));
}
try
{
m_pRs->raw_Close();
//病人玻片信息表
m_pRs->Open("SELECT * FROM BacilusDetect.dbo.PatientSlideInfo",_variant_t((IDispatch*)m_pCon),adOpenStatic,adLockOptimistic,adCmdText);
m_pRs->AddNew();//添加一条新记录
m_pRs->Fields->GetItem(_variant_t("SlideID"))->Value=(_bstr_t)m_SlideBoxData.SlideInfo.strSlideID;
m_pRs->Fields->GetItem(_variant_t("Type"))->Value=(_bstr_t)m_SlideBoxData.SlideInfo.strType;
_variant_t var;
var.vt=VT_DATE;
var.date=int(m_SlideBoxData.SlideInfo.dtDetectData);
m_pRs->Fields->GetItem(_variant_t("DetectData"))->Value=(_bstr_t)var;
_variant_t vart;
vart.vt=VT_DATE;
vart.date=DATE(m_SlideBoxData.SlideInfo.dtDetectTime);
m_pRs->Fields->GetItem(_variant_t("DetectTime"))->Value=(_bstr_t)vart;
m_pRs->Fields->GetItem(_variant_t("Quantity"))->Value=(_bstr_t)m_SlideBoxData.SlideInfo.strQuantity;
m_pRs->Fields->GetItem(_variant_t("StayTime"))->Value=(_bstr_t)m_SlideBoxData.SlideInfo.strStayTime;
m_pRs->Fields->GetItem(_variant_t("Method"))->Value=(_bstr_t)m_SlideBoxData.SlideInfo.strMethod;
m_pRs->Fields->GetItem(_variant_t("SendDoctor"))->Value=(_bstr_t)m_SlideBoxData.SlideInfo.strSendDoctor;
m_pRs->Fields->GetItem(_variant_t("Judge"))->Value=(_bstr_t)m_SlideBoxData.SlideInfo.strJudge;
m_pRs->Fields->GetItem(_variant_t("DetectResult"))->Value=(_bstr_t)m_SlideBoxData.SlideInfo.strDetectResult;
m_pRs->Fields->GetItem(_variant_t("BacilusDensity"))->Value=(_bstr_t)m_SlideBoxData.SlideInfo.strBacilusDensity;
m_pRs->Fields->GetItem(_variant_t("FOVCount"))->Value=(_bstr_t)m_SlideBoxData.nFOVCount;
m_pRs->Fields->GetItem(_variant_t("bScan"))->Value=(_bstr_t)m_SlideBoxData.bScan;
m_pRs->Fields->GetItem(_variant_t("bJudge"))->Value=(_bstr_t)m_SlideBoxData.bJudge;
m_pRs->Fields->GetItem(_variant_t("TargetCount"))->Value=(_bstr_t)GetTargetCountInSlide();
m_pRs->Fields->GetItem(_variant_t("JudgedTargetCount"))->Value=(_bstr_t)GetJudgedTargetCountInSlide();
m_pRs->Update();
AfxMessageBox(_T("病人玻片信息表保存成功!"));
}
catch(...)
{
AfxMessageBox(_T("病人玻片信息表保存失败!"));
}
try
{
m_pRs->raw_Close();
//病人报告信息表
m_pRs->Open("SELECT * FROM BacilusDetect.dbo.PatientRepInfo",_variant_t((IDispatch*)m_pCon),adOpenStatic,adLockOptimistic,adCmdText);
m_pRs->AddNew();//添加一条新记录
m_pRs->Fields->GetItem(_variant_t("ReportDoctor"))->Value=(_bstr_t)m_SlideBoxData.SlideInfo.strReportDoctor;
_variant_t varr;
varr.vt=VT_DATE;
varr.date=int(m_SlideBoxData.SlideInfo.dtReportData);
m_pRs->Fields->GetItem(_variant_t("ReportData"))->Value=(_bstr_t)varr;
m_pRs->Fields->GetItem(_variant_t("CompareJudge"))->Value=(_bstr_t)m_SlideBoxData.SlideInfo.strCompareJudge;
m_pRs->Fields->GetItem(_variant_t("CompareDetectResult"))->Value=(_bstr_t)m_SlideBoxData.SlideInfo.strCompareDetectResult;
m_pRs->Fields->GetItem(_variant_t("CompareBacilusDensity"))->Value=(_bstr_t)m_SlideBoxData.SlideInfo.strCompareBacilusDensity;
m_pRs->Fields->GetItem(_variant_t("SlideID"))->Value=(_bstr_t)m_SlideBoxData.SlideInfo.strSlideID;
_variant_t var;
var.vt=VT_DATE;
var.date=int(m_SlideBoxData.SlideInfo.dtDetectData);
m_pRs->Fields->GetItem(_variant_t("DetectData"))->Value=(_bstr_t)var;
_variant_t vart;
vart.vt=VT_DATE;
vart.date=DATE(m_SlideBoxData.SlideInfo.dtDetectTime);
m_pRs->Fields->GetItem(_variant_t("DetectTime"))->Value=(_bstr_t)vart;
//.........这里部分代码省略.........