_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());
|
用户1584993 2010-5-17 15:04
用户130985 2007-12-24 13:25
I want to collect them.
Thank you!