我做了个多层的数据库应用软件,服务器端放了TADOConnection、TADOQuery、TDataSetProvider;客户端放了TSocketConnection、TClientDataSet1、TDataSource;现在访问和修改数据都很正常,但在添加记录时会提示服务器端的数据集出现错误:Cannot perform this operation on an open dataset。如果说要关闭该数据集则如何关闭?但如果是多用户则又如何解决(关闭该数据集后可能会影响他人使用)?高分求解(分不够再加)。代码如下:
  sql:='Insert into Personinfo (TypeMark,Name,EName) value(';
  sql:=sql+Edit1.Text+',';
  sql:=sql+Edit2.Text+',';
  sql:=sql+Edit3.Text+')';
  DataModule1.ClientDataSet1.Close;
  DataModule1.ClientDataSet1.CommandText:=sql;
  DataModule1.ClientDataSet1.Execute;

解决方案 »

  1.   

    DataSetProvider--Options--poAllowCommandText
      

  2.   

    你试试在DataSetProvider的BeforeExcute事件里关闭数据集看看Occurs before the provider passes an execute command to its dataset.Delphi syntax:property BeforeExecute: TRemoteEvent;C++ syntax:__property TRemoteEvent BeforeExecute = {read=FBeforeExecute, write=FBeforeExecute};DescriptionWrite a BeforeExecute event handler to respond to custom information from a client dataset before executing a query or stored procedure. Any parameter values supplied by the client dataset with the Execute command are applied before this event.BeforeExecute is part of the mechanism by which a provider and a client dataset communicate information when executing queries or stored procedures that do not return cursors. When the provider is part of a stateless application server, this mechanism allows the provider and the client dataset to communicate persistent state information.When the client dataset抯 Execute method is called, the following events occur:1. The client dataset receives a BeforeExecute event, where it can encode custom information into an OleVariant.
    2. The provider receives a BeforeExecute event, where the OleVariant from the client dataset appears as the OwnerData parameter. The provider can respond to or change that information before passing the execute command on to its dataset. 
    3. The provider dispatches its Execute method to execute a query or stored procedure.
    4. The provider receives an AfterExecute event, where it can encode custom information into its OwnerData parameter or respond to information from the BeforeExecute event handler.5. The client dataset receives an AfterExecute event, where it can respond to the custom information returned by the provider in its AfterExecute event handler.
      

  3.   

    DataSetProvider--Options--poAllowCommandText这个时必须的,但还有关键技术,remotedatamodule中的query的active必须为false
    而且其sql属性不能为空,该填的还得填,