金
金风吹雪
Unregistered / Unconfirmed
GUEST, unregistred user!
unit uClassTab;
......
type
TTab=class(TObject)
private
FCunQry: TADOQuery;
public
constructor create; overload;
destructor destroy; override;
property CunQry:TADOQuery read FCunQry;
procedure AllQry(AllQryName:string);
procedure TabShow(ShowName:string);
end;
procedure TTab.AllQry(AllQryName:string);
const
strA='Provider=Microsoft.Jet.OLEDB.4.0;Data Source=';
strB=';Persist Security Info=False';
mdbName='ClimateNMDat.mdb';
begin
FCunQry.ConnectionString:=strA+ExtractFilePath(ParamStr(0))+mdbName+strB;
with FCunQry do
begin
Close;
SQL.Clear;
SQL.Add('select * from '+AllQryName+' order by year');
open;
end;
end;
constructor TTab.create;
begin
FCunQry:=TADOQuery.Create(nil);
end;
destructor TTab.destroy;
begin
if FCunQry<>Nil then FCunQry.Destroy;
inherited;
end;
procedure TTab.TabShow(ShowName:string);
begin
AllQry(showName);
end;
=====================
界面
var
s:TTab;
.....
procedure TfrmMain.FormShow(Sender: TObject);
begin
s:=TTab.create;
......
end;
procedure TfrmMain.tvSelect(strName:string);
begin
s.TabShow(stRName);
ds.DataSet:=s.CunQry;//ds:是TDataSource
dbg.DataSource:=ds;//dbg:是TDBGrid
end;
function TfrmMain.tvTTreeNode:string;
var
parent,child:string;
begin
....
if (StrToInt(parent)>=0) and (StrToInt(child)>=0) then
Result:='R'+parent+child
else
Result:='R0101';
end;
procedure TfrmMain.tvChange(Sender: TObject; Node: TTreeNode);
begin
if (tv.Selected.Parent.Index>=0) and (tv.Selected.Index>=0) then
tvSelect(tvTTreeNode);
end;
procedure TfrmMain.pmInsertClick(Sender: TObject);
begin
if (tv.Selected.Parent.Index>=0) and (tv.Selected.Index>=0) then
begin
dbg.DataSource.DataSet.Insert;
end;
end;
============================
我的问题是:
在TDBGrid中显示的是按
SQL.Add('select * from '+AllQryName+' order by year');
排列的数据,即从小到大(按‘year’字段);
当我要插入一条记录时(在TDBGrid中编辑,当激活数据时),显示的是把插入的记录数据(在TDBGrid中)放在了最后,而不是按照上述(由小到大)排列的。
我想解决:在那里插入记录就显示在那里,怎样解决这个问题?
......
type
TTab=class(TObject)
private
FCunQry: TADOQuery;
public
constructor create; overload;
destructor destroy; override;
property CunQry:TADOQuery read FCunQry;
procedure AllQry(AllQryName:string);
procedure TabShow(ShowName:string);
end;
procedure TTab.AllQry(AllQryName:string);
const
strA='Provider=Microsoft.Jet.OLEDB.4.0;Data Source=';
strB=';Persist Security Info=False';
mdbName='ClimateNMDat.mdb';
begin
FCunQry.ConnectionString:=strA+ExtractFilePath(ParamStr(0))+mdbName+strB;
with FCunQry do
begin
Close;
SQL.Clear;
SQL.Add('select * from '+AllQryName+' order by year');
open;
end;
end;
constructor TTab.create;
begin
FCunQry:=TADOQuery.Create(nil);
end;
destructor TTab.destroy;
begin
if FCunQry<>Nil then FCunQry.Destroy;
inherited;
end;
procedure TTab.TabShow(ShowName:string);
begin
AllQry(showName);
end;
=====================
界面
var
s:TTab;
.....
procedure TfrmMain.FormShow(Sender: TObject);
begin
s:=TTab.create;
......
end;
procedure TfrmMain.tvSelect(strName:string);
begin
s.TabShow(stRName);
ds.DataSet:=s.CunQry;//ds:是TDataSource
dbg.DataSource:=ds;//dbg:是TDBGrid
end;
function TfrmMain.tvTTreeNode:string;
var
parent,child:string;
begin
....
if (StrToInt(parent)>=0) and (StrToInt(child)>=0) then
Result:='R'+parent+child
else
Result:='R0101';
end;
procedure TfrmMain.tvChange(Sender: TObject; Node: TTreeNode);
begin
if (tv.Selected.Parent.Index>=0) and (tv.Selected.Index>=0) then
tvSelect(tvTTreeNode);
end;
procedure TfrmMain.pmInsertClick(Sender: TObject);
begin
if (tv.Selected.Parent.Index>=0) and (tv.Selected.Index>=0) then
begin
dbg.DataSource.DataSet.Insert;
end;
end;
============================
我的问题是:
在TDBGrid中显示的是按
SQL.Add('select * from '+AllQryName+' order by year');
排列的数据,即从小到大(按‘year’字段);
当我要插入一条记录时(在TDBGrid中编辑,当激活数据时),显示的是把插入的记录数据(在TDBGrid中)放在了最后,而不是按照上述(由小到大)排列的。
我想解决:在那里插入记录就显示在那里,怎样解决这个问题?