M
micro73
Unregistered / Unconfirmed
GUEST, unregistred user!
我正用win98+delphi6.0 update2+ado开发三层结构数据管理系统,后台数据库为MS SQL2000。
仿照李sir《系统篇》中第5章“鱼与熊掌兼得法”中的例子(他用的是BDE),想用ADO实现
少量多次取数据到客户端,出现数据表未active的问题。代码如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, DBGrids, ExtCtrls, DBCtrls, DB, DBClient, MConnect,
SConnect, StdCtrls;
type
TForm1 = class(TForm)
SocketConnection1: TSocketConnection;
ClientDataSet1: TClientDataSet;
DataSource1: TDataSource;
DBNavigator1: TDBNavigator;
DBGrid1: TDBGrid;
Button1: TButton;
procedure ClientDataSet1BeforeGetRecords(Sender: TObject;
var OwnerData: OleVariant);
procedure Button1Click(Sender: TObject);
procedure ClientDataSet1AfterGetRecords(Sender: TObject;
var OwnerData: OleVariant);
procedure FormActivate(Sender: TObject);
procedure FormDeactivate(Sender: TObject);
private
bTrueEof:Boolean;
vOwnerData:OleVariant;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TForm1 }
procedure TForm1.ClientDataSet1BeforeGetRecords(Sender: TObject;
var OwnerData: OleVariant);
begin
OwnerData:=vOwnerData;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
abk:TBookMark;
begin
try
if (not bTrueEof) then
begin
try abk:=ClientDataSet1.GetBookmark;
if (ClientDataSet1.GetNextPacket < ClientDataSet1.PacketRecords) then
bTrueEof:=True;
ClientDataSet1.Last;
vOwnerData:=ClientDataSet1.FieldByName('工作编号').Value;
ClientDataSet1.GotoBookmark(abk);
ClientDataSet1.Next;
finally
ClientDataSet1.FreeBookmark(abk);
end;
end;
Except
on Exception do;
end;
end;
procedure TForm1.ClientDataSet1AfterGetRecords(Sender: TObject;
var OwnerData: OleVariant);
var
CurRecord: TBookMark;
begin
try
with Sender as TClientDataSet do
begin
CurRecord := GetBookmark;
try
Last;
vOwnerData := FieldByName('工作编号').Value; //出问题行
GotoBookmark(CurRecord); { return to current record }
finally
FreeBookmark(CurRecord);
end;
end;
except
on Exception do;
end;
end;
procedure TForm1.FormActivate(Sender: TObject);
begin
SocketConnection1.Connected := True;
ClientDataSet1.Active := True;
end;
procedure TForm1.FormDeactivate(Sender: TObject);
begin
ClientDataSet1.Active := False;
SocketConnection1.Connected := False;
end;
end.
各位大虾帮我看看。实现过程:
1.请先在服务器端放入一个TAdoConnection连接到ms sql2000数据库,一个TADODataSet(CacheSize:1000,
采用异步存取),一个TDataSetProvider([poAllowCommandText],ResolveToDataSet:True)
2.客户端一个TSocketConnection,一个TClientDataSet(FetchOnDemand:false,PackRecord:10,CommandText:
select * from 数据表名), 一个TDataSource,一个TDBGrid,一个TDbNavigator,一个TButton),将代码
copy入客户端程序即可。
仿照李sir《系统篇》中第5章“鱼与熊掌兼得法”中的例子(他用的是BDE),想用ADO实现
少量多次取数据到客户端,出现数据表未active的问题。代码如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, DBGrids, ExtCtrls, DBCtrls, DB, DBClient, MConnect,
SConnect, StdCtrls;
type
TForm1 = class(TForm)
SocketConnection1: TSocketConnection;
ClientDataSet1: TClientDataSet;
DataSource1: TDataSource;
DBNavigator1: TDBNavigator;
DBGrid1: TDBGrid;
Button1: TButton;
procedure ClientDataSet1BeforeGetRecords(Sender: TObject;
var OwnerData: OleVariant);
procedure Button1Click(Sender: TObject);
procedure ClientDataSet1AfterGetRecords(Sender: TObject;
var OwnerData: OleVariant);
procedure FormActivate(Sender: TObject);
procedure FormDeactivate(Sender: TObject);
private
bTrueEof:Boolean;
vOwnerData:OleVariant;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TForm1 }
procedure TForm1.ClientDataSet1BeforeGetRecords(Sender: TObject;
var OwnerData: OleVariant);
begin
OwnerData:=vOwnerData;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
abk:TBookMark;
begin
try
if (not bTrueEof) then
begin
try abk:=ClientDataSet1.GetBookmark;
if (ClientDataSet1.GetNextPacket < ClientDataSet1.PacketRecords) then
bTrueEof:=True;
ClientDataSet1.Last;
vOwnerData:=ClientDataSet1.FieldByName('工作编号').Value;
ClientDataSet1.GotoBookmark(abk);
ClientDataSet1.Next;
finally
ClientDataSet1.FreeBookmark(abk);
end;
end;
Except
on Exception do;
end;
end;
procedure TForm1.ClientDataSet1AfterGetRecords(Sender: TObject;
var OwnerData: OleVariant);
var
CurRecord: TBookMark;
begin
try
with Sender as TClientDataSet do
begin
CurRecord := GetBookmark;
try
Last;
vOwnerData := FieldByName('工作编号').Value; //出问题行
GotoBookmark(CurRecord); { return to current record }
finally
FreeBookmark(CurRecord);
end;
end;
except
on Exception do;
end;
end;
procedure TForm1.FormActivate(Sender: TObject);
begin
SocketConnection1.Connected := True;
ClientDataSet1.Active := True;
end;
procedure TForm1.FormDeactivate(Sender: TObject);
begin
ClientDataSet1.Active := False;
SocketConnection1.Connected := False;
end;
end.
各位大虾帮我看看。实现过程:
1.请先在服务器端放入一个TAdoConnection连接到ms sql2000数据库,一个TADODataSet(CacheSize:1000,
采用异步存取),一个TDataSetProvider([poAllowCommandText],ResolveToDataSet:True)
2.客户端一个TSocketConnection,一个TClientDataSet(FetchOnDemand:false,PackRecord:10,CommandText:
select * from 数据表名), 一个TDataSource,一个TDBGrid,一个TDbNavigator,一个TButton),将代码
copy入客户端程序即可。