Why the following code after the execution and close the window, other windows using the Insert language in ClientDataSet.CommandText name to be wrong?

Category: Delphi -> VCL/Component Author: damonning Date: 2013-03-19 10:59:41
 
damonning
2013-03-19 10:59:41
Why the following code after the execution and close the window, other windows using the Insert in the CommandText language name to be wrong?
procedure TZhuanChangEdit.FormCreate (Sender: TObject);
var
bargainCDS: TClientDataSet;
begin
; bargainCDS: = TClientDataSet.Create (nil);
with bargainCDS do
begin
; RemoteServer: = DM_Client.CDSRemote.RemoteServer;
ProviderName: = DM_Client.CDSRemote.ProviderName;
; CommandText: = 'select bargain from ylc_database.dbo.bargain'
; + 'where ok = 0 group by bargain';
Open;
while not Eof do
begin
cboBargain.Items.Add (FieldByName ('bargain'). AsString);
Next;
end;
Close;
end;
FreeAndNil (bargainCDS);
end;
h633com
2013-03-19 11:13:47
Since it is connected with a PROVIDER, there is no need to repeat the creation CDS
yanghuapcs000
2013-03-19 11:23:39
added: ClientDataSet are the following code.
RemoteServer: = DM_Client.CDSRemote.RemoteServer;
ProviderName: = DM_Client.CDSRemote.ProviderName;
singxing
2013-03-19 11:40:45
If the code is not executed TZhuanChangEdit.FormCreate no problem.
mxzl2009
2013-03-19 11:51:12
following code issues. Enough points, plus.

unit Unit3;

interface

uses
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; / / a "catastrophic failure" error
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.
gdfsdxsh
2013-03-19 12:01:28
The above code first run Button2 then execute Button1