簡介
提交的sql查詢字元串指針
套用實例
_ConnectionPtr連結集連結即打開數據庫
m_SqlConnection.CreateInstance("ADODB.Connection");
// strWay="driver={SQL Server};Server=" + sqlname + ";DATABASE=MyDataBase;UID=" + sqluser + ";PWD=" + sqlpass;
strWay="driver={SQL Server};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 城市 IS NOT NULL"),
(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,"DELETE FROM 接收簡訊 WHERE ID=%d",index);
m_pCommand->CommandText=buf; //命令字串。
m_pCommand->Execute(&vNULL,&vNULL,adCmdText);///執行命令。
_ParameterPtr 參數集主要用於存儲過程
_ParameterPtr param;
param=m_pCommand->CreateParameter(_bstr_t("@user"),adVarChar,adParamInput,20);
param->Value=_variant_t(logname);.
m_pCommand->Parameters->Append(param);
_variant_t vNULL;
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);
CString strFind;
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);