CString sql="insert into department( dept_id,dept_name,dept_parent_id) values ('"+deptid+"','"+deptname+"','"+parentId+"')";
try
{
_variant_t RecordsAffected;
m_pConnection->Execute( sql.AllocSysString(),&RecordsAffected,adCmdUnknown);
}catch(_com_error e )
{ AfxMessageBox( e.ErrorMessage() );
}这段程序有IDispatch Error的错误,请问用_ConnectionPtr怎么样执行Execute呀?

解决方案 »

  1.   

    有没有先m_pConnection->Open(...)一下
      

  2.   

    open了的,查询用_RecordsetPtr中用了m_pConnection成功了的
      

  3.   

    插入的值类型是否与数据库表的结构相同,或是有非空的字段没有赋值,先把你的sql语句试试
      

  4.   

    _pConnection->Execute( sql.AllocSysString(),&RecordsAffected,adCmdText);
    or 
    _pConnection->Execute( sql,&RecordsAffected,adCmdText);
      

  5.   

    _pConnection->Execute( sql.AllocSysString(),&RecordsAffected,adCmdText);
    or 
    _pConnection->Execute( sql,&RecordsAffected,adCmdText);