怎样使用ADO中的Command的参数查询,我得代码总有异常???

leafinwind 2001-11-19 05:50:14
这个函数主要测试通过一个带参数的Command对象
插入一条数据,但总是出错,
那位大虾帮我看看,谢了先

BOOL CDBTools::CDBAlarmRec::InsertDirect(LPCTSTR lpszZCID,
LPCTSTR lpszZCName,
CTime& tAlarmTime,
LPCTSTR lpszExplain,
LPCTSTR lpszState )
{
BOOL bResult = FALSE;
HRESULT hr;
_CommandPtr pCommand;
_ParameterPtr pParam;
CString strSQL;
//1.设置命令对象
hr = pCommand.CreateInstance(__uuidof(Command));
if( SUCCEEDED(hr) ){
pCommand->ActiveConnection = m_pConn;
pParam = pCommand->CreateParameter("ParamID",
adInteger,adParamInputOutput,EFL_ID);
pCommand->Parameters->Append(pParam);
pParam = pCommand->CreateParameter("ParamZCID",
adVarChar,adParamInput,EFL_ZCID);
pCommand->Parameters->Append(pParam);
pParam = pCommand->CreateParameter("ParamZCName",
adVarChar,adParamInput,EFL_ZCNAME);
pCommand->Parameters->Append(pParam);
pParam = pCommand->CreateParameter("ParamAlarmTime",
adDate,adParamInput,EFL_ALARMTIME);
pCommand->Parameters->Append(pParam);
pParam = pCommand->CreateParameter("ParamExplain",
adVarChar,adParamInput,EFL_EXPLAIN);
pCommand->Parameters->Append(pParam);
pParam = pCommand->CreateParameter("ParamState",
adVarChar,adParamInput,EFL_STATE);
pCommand->Parameters->Append(pParam);
strSQL.Format("Insert Into %s (ZCID,ZCName,AlarmTime,Explain,State)
Values (:ParamZCID,:ParamZCName,:ParamAlarmTime
,:ParamExplain,:ParamState)",m_strTableName);
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:这样的参数形式是否正确???

pCommand->PutCommandText(_bstr_t(strSQL));

pCommand->Parameters->GetItem(_variant_t("ParamZCID"))
->PutValue(_variant_t(lpszZCID));
pCommand->Parameters->GetItem(_variant_t("ParamZCName"))
->PutValue(_variant_t(lpszZCName));
COleDateTime varDateTime(tAlarmTime.GetTime());
pCommand->Parameters->GetItem(_variant_t("ParamAlarmTime"))
->PutValue(_variant_t(varDateTime));
pCommand->Parameters->GetItem(_variant_t("ParamExplain"))
->PutValue(_variant_t(lpszExplain));
pCommand->Parameters->GetItem(_variant_t("ParamState"))
->PutValue(_variant_t(lpszState));
VARIANT varRecords;
VARIANT varParameters;

pCommand->Execute(&varRecords,&varParameters,adCmdText);
: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:这句总有异常

}

return bResult;
}
...全文
43 点赞 收藏 回复
写回复
回复

还没有回复,快来抢沙发~

发动态
发帖子
VC/MFC
创建于2007-09-28

7898

社区成员

42.1w+

社区内容

VC/MFC相关问题讨论
社区公告
暂无公告