本文整理汇总了C++中_ConnectionPtr::Execute方法的典型用法代码示例。如果您正苦于以下问题:C++ _ConnectionPtr::Execute方法的具体用法?C++ _ConnectionPtr::Execute怎么用?C++ _ConnectionPtr::Execute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类_ConnectionPtr
的用法示例。
在下文中一共展示了_ConnectionPtr::Execute方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FieldToOtherField
/*
µ±nStale=1ʱ ×Ö·û×ֶηµ»Ø×Ö·û×Ö¶Î
µ±nStale=2ʱ ÊýÖµ×ֶηµ»Ø×Ö·û×Ö¶Î
µ±nStale=3ʱ ÈÕÆÚ×ֶηµ»Ø×Ö·û×Ö¶Î
*/
CString RxADO::FieldToOtherField(CString cDataBaseName, CString cFieldName, CString cValue, CString cReturnField, int nStale=1)
{
CString sSQL,sRTValue;
_RecordsetPtr Fieldrst;
Fieldrst.CreateInstance(__uuidof(Recordset));
Fieldrst.CreateInstance(__uuidof(Recordset));
if(nStale==1) //×Ö·û×ֶηµ»Ø×Ö·û×Ö¶Î
sSQL.Format("SELECT * FROM %s WHERE %s='%s'",cDataBaseName,cFieldName,cValue);
if(nStale==2)//ÊýÖµ×ֶηµ»Ø×Ö·û×Ö¶Î
sSQL.Format("SELECT * FROM %s WHERE %s=%s",cDataBaseName,cFieldName,cValue);
if(nStale==3)//ÈÕÆÚ×ֶηµ»Ø×Ö·û×Ö¶Î
sSQL.Format("SELECT * FROM %s WHERE %s=#%s#",cDataBaseName,cFieldName,cValue);
try{
Fieldrst=cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
}
catch(_com_error&e)
{
GetADOErrors(e);
return "";
}
if(GetRecordCount(Fieldrst)<=0)
return "";
_variant_t vValue=Fieldrst->GetCollect((_bstr_t)cReturnField);
if(vValue.vt==VT_EMPTY)
return "";
sRTValue=(char*)(_bstr_t)vValue;
sRTValue.TrimRight();
sRTValue.TrimLeft();
return sRTValue;
}
示例2: ADOConExec
int CCommDBOper::ADOConExec(_ConnectionPtr &pCon,const CString strCmdSql,CString strDcrCmd,int iWarn)
{
//函数功能说明: 由pCon(Connection)对象执行指定SQL命令
//pCon 数据库连接对象
//strCmdSql 要执行SQL的命令语句
//strDcrCmd是对要使用SQL命令的描述
if (ADOConIsOpened(pCon,iWarn) != RET_OK) //判断当前连接对象是否已打开
{
WarnMessage("指定数据库对象未连接,退出!",iWarn);
return RET_FAILED;
}
try
{
pCon->Execute(_bstr_t(strCmdSql),NULL,adCmdText);
}
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",strDcrCmd,strCmdSql,e.ErrorMessage());
WarnMessage(errormessage,iWarn);///显示错误信息
return RET_FAILED;
}
return RET_OK;
}
示例3: ExecuteDML
DWORD CNHSQLServerDBO::ExecuteDML(const _ConnectionPtr &pConnection, const wchar_t *const pwchSQL, int *const pnRowsInvolved/*=NULL*/)
{
assert(NULL != pConnection);
assert(NULL != pwchSQL);
DWORD dwReturn(0x00);
try
{
_variant_t vRA;
pConnection->Execute((_bstr_t)pwchSQL, &vRA, adCmdText);
if (NULL != pnRowsInvolved)
{
*pnRowsInvolved = static_cast<int>(vRA);
}
}
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::ExecuteDML发生错误(执行%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;
}
示例4: tableExists
BOOL newproject::tableExists(_ConnectionPtr pCon, CString tbn)
{
if(pCon==NULL || tbn=="")
return false;
_RecordsetPtr rs;
if(tbn.Left(1)!="[")
tbn="["+tbn;
if(tbn.Right(1)!="]")
tbn+="]";
try {
rs=pCon->Execute(_bstr_t(tbn),NULL,adCmdTable);
rs->Close();
return true;
}
catch(_com_error e)
{
return false;
}
}
示例5: GetRecordSet
void CMorphaResDlg::GetRecordSet(_RecordsetPtr &rs, int row1, int row2)
{
ASSERT(row1>=0&&row2>=0&&row1<=row2);
CString strSQL;
CString tablename;
if(((CMorphaDataRetriveDlg*)(GetParent()->GetParent()->GetParent()))->IsInqueryState())
tablename = "morphaforinquery";
else
tablename = "morphafordisplay";
if(row1 == 0 )
{
strSQL.Format("select * from (select top %d * from %s) a "
,row2,tablename);
}
else
{
strSQL.Format("select * from (select top %d * from %s) a \
where pdetectno not in(select top %d pdetectno from %s)"
,row2,tablename,row1,tablename);
}
if(rs == NULL)
rs.CreateInstance("adodb.recordset");
rs = theConnection->Execute((LPCSTR)strSQL,NULL,adCmdText);
}
示例6: OnInitDialog
BOOL CMorphaResDlg::OnInitDialog()
{
CPropertyPage::OnInitDialog();
CMainFrame* pMainFrm=(CMainFrame*)AfxGetMainWnd();
CMorphaDataRetriveDlg& dlg = *(pMainFrm->m_pWndMorphadlg);
CString strSQLCRMfi("select morpharesult.* into morphafordisplay \
from morpharesult,basicinfo,morphaimage,spermchait,morpharesultratio \
where morpharesult.pdetectno = basicinfo.pdetectno \
and morpharesult.pdetectno = morphaimage.pdetectno \
and morpharesult.pdetectno = spermchait.pdetectno \
and morpharesult.pdetectno = morpharesultratio.pdetectno");
try
{
if(IsTableExist(theConnection, "morphafordisplay") == true)
{
theConnection->Execute((LPCTSTR)"drop table morphafordisplay",NULL,adCmdText);
}
theConnection->Execute((LPCTSTR)strSQLCRMfi,NULL,adCmdText);
CString strGetN("select count(*) from morphafordisplay");
_RecordsetPtr rs=theConnection->Execute((LPCSTR)strGetN,NULL,adCmdText);
dlg.m_dp[0].nCurPage = 1;
dlg.m_dp[0].nTotalRecord=rs->GetCollect((long)0).iVal;
dlg.m_dp[0].nPageRecord = NUMPERPAGE;
dlg.m_dp[0].nTotalPage = dlg.m_dp[0].nTotalRecord / dlg.m_dp[0].nPageRecord +
(dlg.m_dp[0].nTotalRecord % dlg.m_dp[0].nPageRecord!=0);
CString queryinfo;
queryinfo.Format("共查询到%d条记录",dlg.m_dp[0].nTotalRecord);
dlg.SetDlgItemText(IDC_STATIC_QUERY,queryinfo);
if(dlg.m_dp[0].nTotalRecord == 0 )
{
CMainFrame* pMainFrm=(CMainFrame*)AfxGetMainWnd();
pMainFrm->m_pWndMorphadlg->GetDlgItem(IDC_BTN_FIRSTPAGE)->EnableWindow(FALSE);
pMainFrm->m_pWndMorphadlg->GetDlgItem(IDC_BTN_PREPAGE)->EnableWindow(FALSE);
pMainFrm->m_pWndMorphadlg->GetDlgItem(IDC_BTN_NEXTPAGE)->EnableWindow(FALSE);
pMainFrm->m_pWndMorphadlg->GetDlgItem(IDC_BTN_LASTPAGE)->EnableWindow(FALSE);
pMainFrm->m_pWndMorphadlg->GetDlgItem(IDC_PAGENUM)->EnableWindow(FALSE);
return FALSE;
}
int lowRow, upRow;
dlg.GetPageBound(1,lowRow,upRow,dlg.m_dp[0]);
GetRecordSet(rs,lowRow,upRow);
int n=dlg.m_resdlg.m_wndMorphaDataList.SetData(rs);
queryinfo.Format("第 %d / %d 页",dlg.m_dp[0].nCurPage,dlg.m_dp[0].nTotalPage);
dlg.SetDlgItemText(IDC_PAGENUM,queryinfo);
dlg.GetDlgItem(IDC_BTN_FIRSTPAGE)->EnableWindow(dlg.m_dp[dlg.IsInqueryState()].nCurPage != 1);
dlg.GetDlgItem(IDC_BTN_PREPAGE)->EnableWindow(dlg.m_dp[dlg.IsInqueryState()].nCurPage != 1);
dlg.GetDlgItem(IDC_BTN_NEXTPAGE)->EnableWindow(dlg.m_dp[dlg.IsInqueryState()].nCurPage != dlg.m_dp[dlg.IsInqueryState()].nTotalPage);
dlg.GetDlgItem(IDC_BTN_LASTPAGE)->EnableWindow(dlg.m_dp[dlg.IsInqueryState()].nCurPage != dlg.m_dp[dlg.IsInqueryState()].nTotalPage );
}
catch (_com_error& e)
{
MessageBox(e.Description());
return FALSE;
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
示例7: OnClickListMorphadata
void CMorphaResDlg::OnClickListMorphadata(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
LV_COLUMN lc;
lc.mask = LVCF_TEXT ;
TCHAR pszText[40];
lc.pszText = pszText;
lc.cchTextMax = sizeof(pszText)/sizeof(pszText[0]);
int nCol = 0;
while (m_wndMorphaDataList.GetColumn(nCol,&lc))
{
if(CString(lc.pszText) == TEXT("检测号"))
break;
++nCol;
}
CString str=m_wndMorphaDataList.GetItemText(pNMListView->iItem,nCol);
if(str == "") return;
CString strSQLinfo("select distinct *,basicinfo.pdetectno as 'pDetectno' from basicinfo,spermchait\
where basicinfo.pdetectno=spermchait.pdetectno and \
basicinfo.pdetectno='");
strSQLinfo= strSQLinfo + str + CString("'");
CPropertySheet* pSheet=(CPropertySheet*)GetParent();
CStatic* pStatic=(CStatic*)pSheet->GetParent();
CMorphaDataRetriveDlg* pDlg=(CMorphaDataRetriveDlg*)pStatic->GetParent();
try
{
_variant_t var;
COleDateTime pddt;
_RecordsetPtr rs=theConnection->Execute((LPCTSTR)strSQLinfo,NULL,adCmdText);
var = rs->GetCollect("pDetectno");
pDlg->m_strEditDetectNO = (char*)(_bstr_t)var;
// pDlg->m_strEditDetectNO.TrimLeft();
// pDlg->m_strEditDetectNO.TrimRight();
var = rs->GetCollect("pCaseNO");
pDlg->m_strEditCaseNO = (char*)(_bstr_t)var;
// pDlg->m_strEditCaseNO.TrimLeft();
// pDlg->m_strEditCaseNO.TrimRight();
var = rs->GetCollect("pname");
pDlg->m_strEditName = (char*)(_bstr_t)var;
// pDlg->m_strEditName.TrimLeft();
// pDlg->m_strEditName.TrimRight();
var = rs->GetCollect("pspermvolume");
pDlg->m_strEditSpermVolume = (char*)(_bstr_t)var;
// pDlg->m_strEditSpermVolume.TrimLeft();
// pDlg->m_strEditSpermVolume.TrimRight();
var = rs->GetCollect("page");
pDlg->m_strEditAge = (char*)(_bstr_t)var;
// pDlg->m_strEditAge.TrimLeft();
// pDlg->m_strEditAge.TrimRight();
pddt=rs->GetCollect("pdetectdatetime");
pDlg->m_oledateDetectDate.SetDate(pddt.GetYear(),pddt.GetMonth(),pddt.GetDay());
pDlg->m_oletimeDetectTime.SetTime(pddt.GetHour(),pddt.GetMinute(),pddt.GetSecond());
var = rs->GetCollect("pSampleNO");
pDlg->m_strEditSampleNO = (char*)(_bstr_t)var;
// pDlg->m_strEditSampleNO.TrimLeft();
// pDlg->m_strEditSampleNO.TrimRight();
var = rs->GetCollect("pdilutionratio");
pDlg->m_strEditDilutionRatio = (char*)(_bstr_t)var;
// pDlg->m_strEditDilutionRatio.TrimLeft();
// pDlg->m_strEditDilutionRatio.TrimRight();
var = rs->GetCollect("pShape");
pDlg->m_strEditShape = (char*)(_bstr_t)var;
// pDlg->m_strEditShape.TrimLeft();
// pDlg->m_strEditShape.TrimRight();
pddt=rs->GetCollect("pspermgetdatetime");
pDlg->m_oledateSpermGetDate.SetDate(pddt.GetYear(),pddt.GetMonth(),pddt.GetDay());
pDlg->m_oletimeSpermGetTime.SetTime(pddt.GetHour(),pddt.GetMinute(),pddt.GetSecond());
var = rs->GetCollect("pcolor");
pDlg->m_strEditSpermColor = (char*)(_bstr_t)var;
// pDlg->m_strEditSpermColor.TrimLeft();
// pDlg->m_strEditSpermColor.TrimRight();
var = rs->GetCollect("pcohesion");
pDlg->m_strEditCohension = (char*)(_bstr_t)var;
// pDlg->m_strEditCohension.TrimLeft();
// pDlg->m_strEditCohension.TrimRight();
var = rs->GetCollect("pRoomTempera");
pDlg->m_strEditRoomTempera = (char*)(_bstr_t)var;
// pDlg->m_strEditRoomTempera.TrimLeft();
// pDlg->m_strEditRoomTempera.TrimRight();
var = rs->GetCollect("pdaysofabstinency");
pDlg->m_strEditAbstinency = (char*)(_bstr_t)var;
// pDlg->m_strEditAbstinency.TrimLeft();
// pDlg->m_strEditAbstinency.TrimRight();
var = rs->GetCollect("pliquifystate");
pDlg->m_strEditLiquifyState = (char*)(_bstr_t)var;
// pDlg->m_strEditLiquifyState.TrimLeft();
// pDlg->m_strEditLiquifyState.TrimRight();
var = rs->GetCollect("psmell");
pDlg->m_strEditSmell = (char*)(_bstr_t)var;
// pDlg->m_strEditSmell.TrimLeft();
// pDlg->m_strEditSmell.TrimRight();
var = rs->GetCollect("pthickness");
pDlg->m_strEditThickness = (char*)(_bstr_t)var;
// pDlg->m_strEditThickness.TrimLeft();
// pDlg->m_strEditThickness.TrimRight();
var = rs->GetCollect("pph");
pDlg->m_strEditPH = (char*)(_bstr_t)var;
//.........这里部分代码省略.........
示例8: AutoNumber
/*
µ±nStyle=1ʱ Éú³ÉÊý×Ö±àºÅ
µ±nStyle=2ʱ Éú³ÉÁ÷Ë®ÕʺÅ
µ±nStyle=3ʱ Éú³ÉÈÕÆÚʱ¼ä±àºÅ
*/
CString RxADO::AutoNumber(CString sTable, CString sFieldName, CString sCode, int nStyle)
{
_RecordsetPtr AutoNumberrst;
CString sTempNewNumber,sNewNumber,sSQL,sMaxNumber,sOldNumber;
AutoNumberrst.CreateInstance(__uuidof(Recordset));
sSQL.Format("SELECT MAX(%s) as ×î´ó±àºÅ FROM %s",sFieldName,sTable);
try{
AutoNumberrst=cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
}
catch(_com_error & e)
{
GetADOErrors(e);
}
if(nStyle==1) //Êý×Ö±àºÅ
{
if(GetRecordCount(AutoNumberrst)<1)
sNewNumber.Format("1");
else
{
AutoNumberrst->MoveFirst();
_variant_t vtext;
vtext=AutoNumberrst->GetCollect("×î´ó±àºÅ");
if(vtext.vt==VT_EMPTY||vtext.vt==VT_NULL)
{
sNewNumber.Format("1");
goto end;
}
sMaxNumber=(char*)(_bstr_t)AutoNumberrst->GetCollect("×î´ó±àºÅ");
sNewNumber.Format("%d",atoi(sMaxNumber)+1);
}
}
if(nStyle==2)//Á÷Ë®ÕʺÅ
{
if(GetRecordCount(AutoNumberrst)<1)
sNewNumber.Format("%s00000001",sCode);
else
{
AutoNumberrst->MoveFirst();
_variant_t _bOldNumber=AutoNumberrst->GetCollect("×î´ó±àºÅ");
if(_bOldNumber.vt==VT_NULL || _bOldNumber.vt==VT_EMPTY)
{
sNewNumber.Format("%s00000001",sCode);
goto end;
}
sOldNumber=(char*)(_bstr_t) _bOldNumber;
sMaxNumber=sOldNumber.Mid(3);
sTempNewNumber.Format("%d",atoi(sMaxNumber)+1);
sNewNumber.Format("%s%s",sCode,Padl(sTempNewNumber,8,"0",1));
}
}
if(nStyle==3)//ÈÕÆÚʱ¼ä±àºÅ
{
int nYear,nDay,nMonth;
CString sYear,sDay,sMonth;
CTime tTime;
tTime=tTime.GetCurrentTime();
nYear=tTime.GetYear();
nDay=tTime.GetDay();
nMonth=tTime.GetMonth();
sYear.Format("%d",nYear);
sDay.Format("%d",nDay);
sMonth.Format("%d",nMonth);
sYear=sYear.Mid(2);
sDay=Padl(sDay,2,"0",1);
sMonth=Padl(sMonth,2,"0",1);
if(GetRecordCount(AutoNumberrst)<1)
sNewNumber.Format("%s%s%s%s-000001 ",sCode,sYear,sMonth,sDay);
else
{
_variant_t bh=AutoNumberrst->GetCollect("×î´ó±àºÅ");
if(bh.vt==VT_EMPTY||bh.vt==VT_NULL)
{
sNewNumber.Format("%s%s%s%s-000001 ",sCode,sYear,sMonth,sDay);
goto end;
}
CString sOldDate,sNewDate;
AutoNumberrst->MoveFirst();
sOldNumber=(char*)(_bstr_t)AutoNumberrst->GetCollect("×î´ó±àºÅ");
sOldDate=sOldNumber.Mid(2,6);
sNewDate.Format("%s%s%s",sYear,sMonth,sDay);
if(sOldDate==sNewDate)
{
sMaxNumber=sOldNumber.Mid(9);
sTempNewNumber.Format("%d",atoi(sMaxNumber)+1);
sNewNumber.Format("%s%s%s%s-%s",sCode,sYear,sMonth,sDay,Padl(sTempNewNumber,6,"0",1));
}
else
sNewNumber.Format("%s%s%s%s-000001 ",sCode,sYear,sMonth,sDay);
}
}
end: return sNewNumber;
}