_CommandPtr是一種函式,功能是提交的sql查詢字元串指針。
基本介紹
- 中文名:CommandPtr
- 簡介:提交的sql查詢字元串指針
簡介,套用實例,
簡介
提交的sql查詢字元串指針
套用實例
_ConnectionPtr連結集連結即打開資料庫m_SqlConnection.CreateInstance("ADODB.Connection");//strWay="driver={SQLServer};Server="+sqlname+";DATABASE=MyDataBase;UID="+sqluser+";PWD="+sqlpass;strWay="driver={SQLServer};Server="+sqlname+";DATABASE=調度信息庫";m_SqlConnection->ConnectionTimeout=10;//設定逾時時間為10秒m_SqlConnection->CursorLocation=adUseClient;m_SqlConnection->Open((_bstr_t)strWay,(_bstr_t)sqluser,(_bstr_t)sqlpass,adModeUnknown);_RecordsetPtr記錄集打開數據表(中的記錄)m_SqlRecordset.CreateInstance("ADODB.Recordset");m_SqlRecordset->Open((_variant_t)("SELECT*FROM城市表WHERE省份='"+str+"'AND城市ISNOTNULL"),(IDispatch*)m_SqlConnection,adOpenStatic,adLockOptimistic,adCmdText);_CommandPtr命令集打開數據表即執行命令m_pCommand.CreateInstance("ADODB.Command");m_pCommand->ActiveConnection=m_SqlConnection;m_pCommand->CommandType=adCmdText;vNULL.vt=VT_ERROR;vNULL.scode=DISP_E_PARAMNOTFOUND;sprintf(buf,"DELETEFROM接收簡訊WHEREID=%d",index);m_pCommand->CommandText=buf;//命令字串。m_pCommand->Execute(&vNULL,&vNULL,adCmdText);///執行命令。_ParameterPtr參數集主要用於存儲過程_ParameterPtrparam;param=m_pCommand->CreateParameter(_bstr_t("@user"),adVarChar,adParamInput,20);param->Value=_variant_t(logname);.m_pCommand->Parameters->Append(param);_variant_tvNULL;vNULL.vt=VT_ERROR;vNULL.scode=DISP_E_PARAMNOTFOUND;m_pCommand->Execute(&vNULL,&vNULL,adCmdStoredProc);建議用屬性更簡單m_pCommand->Parameters->Refresh();m_pCommand->Parameters->Item["@user"]->Value=_variant_t(logname);m_pCommand->Parameters->Item["@operation"]->Value=_variant_t(operation);m_pCommand->Parameters->Item["@oper_type"]->Value=_variant_t(oper_type);再如://四種操作欄位的寫入方法m_pRecordset->Collect["名稱"]=_variant_t(m_strName);//m_pRecordset->Fields->Item["名稱"]->Value=_variant_t(m_strName);//m_pRecordset->PutCollect("名稱",_variant_t(m_strName));//m_pRecordset->GetFields()->GetItem("名稱")->PutValue(_variant_t(m_strName));//四種操作欄位的讀取方法m_cmbCity.AddString((_bstr_t)m_SqlRecordset->Collect["城市"]);//m_cmbCity.AddString((_bstr_t)m_SqlRecordset->Fields->Item["城市"]->Value);//m_cmbCity.AddString((_bstr_t)m_SqlRecordset->GetCollect("城市"));//m_cmbCity.AddString((_bstr_t)m_SqlRecordset->GetFields()->GetItem("城市")->GetValue());m_SqlRecordset.CreateInstance("ADODB.Recordset");m_SqlRecordset->CursorLocation=adUseClient;m_SqlRecordset->Open(_variant_t(str),_variant_t((IDispatch*)m_SqlConnection),adOpenStatic,adLockOptimistic,adCmdText);CStringstrFind;strFind.Format("主叫號碼=%s",m_strCheck);strFind.Format("主叫號碼LIKE\'%%%s%%\'",m_strCheck);m_SqlRecordset->Fields->Item["主叫號碼"]->Properties->Item["Optimize"]->Value="True";m_SqlRecordset->Find((_bstr_t)strFind,1,adSearchForward);