_CommandPtr pCommand;
_RecordsetPtr pRecordset;
try
{
HRESULT hr = pCommand.CreateInstance(__uuidof(Command));
if (FAILED(hr))
{
hr=NULL;
AfxMessageBox("can't create an instance of Command");
return;
}
pCommand->ActiveConnection = m_connect;
pCommand->CommandText = (_bstr_t)sql;
hr = pRecordset.CreateInstance(__uuidof(Recordset));
if (FAILED(hr))
{
pRecordset = NULL;
AfxMessageBox("can't create an instance of Recordset");
return;
}
pRecordset=pCommand->Execute(NULL,NULL,adCmdText);
                  pRecordset->Close();
           }

解决方案 »

  1.   

    这段代码 一直出错,我网上查好像 update的执行语句是没有返回值的。那么我该如何关闭记录集
    如何显示 修改后的记录集
      

  2.   

    再用SELECT查询下那条记录即可.确认值是否改变.GetCollect得到你修改的值.匹配下是否正确
      

  3.   

    Execute Method (ADO Command)
    Executes the query, SQL statement, or stored procedure specified in the CommandText or CommandStream property.Syntax
    For a Recordset-returning Command:Set recordset = command.Execute( RecordsAffected, Parameters, Options )
    For a non–recordset-returning Command:command.Execute RecordsAffected, Parameters, Options
    Return Value
    Returns a Recordset object reference, a stream, or Nothing.Parameters
    RecordsAffected 
    Optional. A Long variable to which the provider returns the number of records that the operation affected. The RecordsAffected parameter applies only for action queries or stored procedures. RecordsAffected does not return the number of records returned by a result-returning query or stored procedure. To obtain this information, use the RecordCount property. The Execute method will not return the correct information when used with adAsyncExecute, simply because when a command is executed asynchronously, the number of records affected may not yet be known at the time the method returns. 
    Parameters 
    Optional. A Variant array of parameter values used in conjunction with the input string or stream specified in CommandText or CommandStream. (Output parameters will not return correct values when passed in this argument.) 
    Options 
    Optional. A Long value that indicates how the provider should evaluate the CommandText or the CommandStream property of the Command object. Can be a bitmask value made using CommandTypeEnum and/or ExecuteOptionEnum values. For example, you could use adCmdText and adExecuteNoRecords in combination if you want to have ADO evaluate the value of the CommandText property as text, and indicate that the command should discard and not return any records that might be generated when the command text executes. 
    Notes   Use the ExecuteOptionEnum value adExecuteNoRecords to improve performance by minimizing internal processing.
    If adExecuteStream was specified, the options adAsyncFetch and adAsynchFetchNonBlocking are ignored.
    Do not use the CommandTypeEnum values of adCmdFile or adCmdTableDirect with Execute. These values can only be used as options with the Open and Requery methods of a Recordset.
    Res
    Using the Execute method on a Command object executes the query specified in the CommandText property or CommandStream property of the object.Results are returned in a Recordset (by default) or as a stream of binary information. To obtain a binary stream, specify adExecuteStream in Options, then supply a stream by setting Command.Properties("Output Stream"). An ADO Stream object can be specified to receive the results, or another stream object such as the IIS Response object can be specified. If no stream was specified before calling Execute with adExecuteStream, an error occurs. The position of the stream on return from Execute is provider specific.If the command is not intended to return results (for example, an SQL UPDATE query) the provider returns Nothing as long as the option adExecuteNoRecords is specified; otherwise Execute returns a closed Recordset. Some application languages allow you to ignore this return value if no Recordset is desired.Execute raises an error if the user specifies a value for CommandStream when the CommandType is adCmdStoredProc, adCmdTable, or adCmdTableDirect.If the query has parameters, the current values for the Command object's parameters are used unless you override these with parameter values passed with the Execute call. You can override a subset of the parameters by omitting new values for some of the parameters when calling the Execute method. The order in which you specify the parameters is the same order in which the method passes them. For example, if there were four (or more) parameters and you wanted to pass new values for only the first and fourth parameters, you would pass Array(var1,,,var4) as the Parameters argument.Note   Output parameters will not return correct values when passed in the Parameters argument.
    An ExecuteComplete event will be issued when this operation concludes.Note   When issuing commands containing URLs, those using the http scheme will automatically invoke the Microsoft OLE DB Provider for Internet Publishing. For more information, see Absolute and Relative URLs
      

  4.   

    ado帮助文档里的
    以前电脑里自带完整的
    现在只能从网上下了