ClientSocket1向服务器发送一组数ServerSocket1数据接收后添加到数据库不正确(100分)

  • 主题发起人 主题发起人 silong08
  • 开始时间 开始时间
S

silong08

Unregistered / Unconfirmed
GUEST, unregistred user!
客户端程序
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ComCtrls, ScktComp, DB, Grids, DBGrids, ADODB;

type
TForm1 = class(TForm)
ClientSocket1: TClientSocket;
Label1: TLabel;
Label2: TLabel;
Edip: TEdit;
edport: TEdit;
StatusBar1: TStatusBar;
Memo1: TMemo;
btnConnect: TBitBtn;
btnSent: TBitBtn;
BitBtn1: TBitBtn;
btnDisconnect: TBitBtn;
Memo2: TMemo;
ADOTable1: TADOTable;
DBGrid1: TDBGrid;
DataSource1: TDataSource;
procedure ClientSocket1Connect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket);
procedure btnSentClick(Sender: TObject);
procedure btnConnectClick(Sender: TObject);
procedure btnDisconnectClick(Sender: TObject);
procedure FormCreate(Sender: TObject);



private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}
procedure TForm1.ClientSocket1Connect(Sender: TObject;
Socket: TCustomWinSocket);
begin
StatusBar1.SimpleText := '连接成功';
end;
procedure TForm1.ClientSocket1Read(Sender: TObject;
Socket: TCustomWinSocket);
begin
Memo2.Lines.Add(Socket.ReceiveText);
end;

procedure TForm1.btnSentClick(Sender: TObject);
var
g:integer;
value1:string;
begin
if ClientSocket1.Active then
begin
//g:=g+1;
//value1:=ADOtable1.Fields[0].AsString;
g:=0;
//StrToInt(value1);

while g<30 do
begin
ClientSocket1.Socket.SendText(ADOtable1.Fields[0].AsString+'.');
ADOtable1.next;
g:=g+1;
end;

end;
end;

procedure TForm1.btnConnectClick(Sender: TObject);
begin
if not ClientSocket1.Active then
begin
ClientSocket1.Host := edIp.Text;
ClientSocket1.Port := StrToInt(edPort.Text);
ClientSocket1.Open;
(Sender as TButton).Enabled := false;
btnDisconnect.Enabled := true;
end;

end;

procedure TForm1.btnDisconnectClick(Sender: TObject);
begin
if ClientSocket1.Active then
begin
ClientSocket1.Close;
btnDisconnect.Enabled := false;
btnConnect.Enabled := true;

end;

end;

procedure TForm1.FormCreate(Sender: TObject);
begin

end;

end.

服务器端程序
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ComCtrls, ScktComp, DB, ADODB, ExtCtrls;

type
TForm1 = class(TForm)
ServerSocket1: TServerSocket;
Memo1: TMemo;
StatusBar1: TStatusBar;
Memo2: TMemo;
BitBtn1: TBitBtn;
ADOTable1: TADOTable;
DataSource1: TDataSource;
ADOQuery1: TADOQuery;
BitBtn2: TBitBtn;
Timer1: TTimer;
procedure BitBtn1Click(Sender: TObject);
procedure ServerSocket1ClientConnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ServerSocket1ClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);



private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
S:string;
implementation

{$R *.dfm}

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
if ServerSocket1.Active then
ServerSocket1.Socket.Connections[0].SendText(Memo2.Text);

end;

procedure TForm1.ServerSocket1ClientConnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
StatusBar1.SimpleText := 'connect';
end;

procedure TForm1.ServerSocket1ClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
StatusBar1.SimpleText := 'disconnect';
end;

procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
//var
//S:string;
//S:=Socket.ReceiveText
begin
With ADOQuery1 do
begin
S:=Socket.ReceiveText;
sql.Text:='Select * from 传感器';
open;
insert;
fieldbyname('编号').Value:=s;
post;
end;

//Memo1.Lines.Add( Socket.ReceiveText);
//S:=Socket.ReceiveText;
//adotable1.Open;
// adotable1.Insert;
//ADOtable1.Fields[0].AsString:=Socket.ReceiveText;;
//adotable1.post;
//ADOQuery1.Close;
//ADOQuery1.SQL.Clear;
//ADOQuery1.SQL.Add('USE ZJZB INSERT INTO mission (id,repair_unit,company_Id,tank_Id,total_hour,total_mile,fault_behave,repair_quest,repair_condition,finish_date)values('''+edit2.Text+''','''+edit3.Text+''','''+edit4.Text+''','''+edit5.text+''','''+edit6.Text+''','''+edit7.Text+''','''+edit8.Text+''','''+edit9.Text+''','''+edit10.text+''','''+datetostr(datetimepicker1.Date)+'''');
//ADOQuery1.Execsql
end;

end.


数据库编号
1.
2.3.4.5.6.7.8.9.
10.11.
12.13.
14.15.16.17.
18.19.
20.21.22.
23.24.25.
26.27.
28.28.30.

如果传到
Memo1中是对的为
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
28.
30.
 
后退
顶部