如下代码问题。先执行Button2再执行Button1。分不够再加。unit Unit3;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, DBClient, MConnect, StdCtrls, Grids, DBGrids;type
  TForm1 = class(TForm)
    DCOMConnection1: TDCOMConnection;
    ClientDataSet1: TClientDataSet;
    DataSource1: TDataSource;
    Button1: TButton;
    Button2: TButton;
    ComboBox1: TComboBox;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
 var tmp: TClientDataSet;
begin
   tmp:=TClientDataSet.Create(nil);
   tmp.RemoteServer:=Clientdataset1.RemoteServer;
   tmp.ProviderName:='remotedsp';
   tmp.CommandText:='insert agreement (date,code) values (''2003-4-19'',''t001'')';
   tmp.Execute;  //出现“灾难性故障”错误
   tmp.Free;
end;procedure TForm1.Button2Click(Sender: TObject);
 var tmp: TClientDataSet;
begin
   tmp:=TClientDataSet.Create(nil);
   tmp.RemoteServer:=ClientDataSet1.RemoteServer;
   tmp.ProviderName:='remotedsp';
   tmp.CommandText:='select sim_name from sg_sales.dbo.id08 order by sim_name';
   tmp.Open;
   combobox1.Items.Clear;
   while not tmp.Eof do
   begin
      combobox1.Items.Add(tmp['sim_name']);
      tmp.Next;
   end;
   tmp.Close;
   freeandnil(tmp);
end;end.

解决方案 »

  1.   

    'insert agreement (date,code) values (''2003-4-19'',''t001'')'这句SQL是否正确
      

  2.   

    SQL语句是正确的。
    tmp.CommandText:='insert agreement (date,code) values (''2003-4-19'',''t001'')';
    改为
    tmp.CommandText:='select ...';
    就没有问题。
      

  3.   

    在Provider的Options中加入“AllowCommandText”试试。你可以调试一下服务端以确定错误。
      

  4.   

    用INSERT 方法+POST方法试试
      

  5.   

    Erice(白雪公猪)、 INeedCa(缺钙) 我知道你们是好心,但还是请你们看清楚点。
      

  6.   

    在remotedsp的Options中加入“AllowCommandText”.
      

  7.   

    我有在Options中加入“AllowCommandText”。
      

  8.   

    SQL语句是正确的。
    tmp.CommandText:='insert agreement (date,code) values (''2003-4-19'',''t001'')';
    改为
    tmp.CommandText:='select ...';
    就没有问题。
      

  9.   

    Run->Parameters->Host Application C:\WINDOWS\SYSTEM32\dllhost.exe
    Parameters :/ProcessID:{D6DFC270-FF07-4BF7-A6E4-970C0BD27664}-- your application GUID
      

  10.   

    自己搞定。
    tmp:=tclientdataset.create(nil);
    tmp.remoteserver:=...;
    tmp.providername:=...;
    tmp.commandtext:=...;
    tmp.execute/tmp.open;
    ...
    tmp.close;
    tmp.remoteserver.close;  //这一行必须加
    freeandnil(tmp);