有表(SQL SERVER)
---------
drop table tb
gocreate table tb (id int identity(1,1), a varchar(10))
go
insert tb(a)
select '01'
union all select '02'
union all select '03'
union all select '04'
union all select '05'
go
select * from tb
go
用TADOQUERY来OPEN这个表.(SQL:select * from tb order by a)现在想实现的功能是:
1,点击箭头按钮,让DBGRID相邻的两行调换位置,
2,并保存调换位置后的顺序;
---------
drop table tb
gocreate table tb (id int identity(1,1), a varchar(10))
go
insert tb(a)
select '01'
union all select '02'
union all select '03'
union all select '04'
union all select '05'
go
select * from tb
go
用TADOQUERY来OPEN这个表.(SQL:select * from tb order by a)现在想实现的功能是:
1,点击箭头按钮,让DBGRID相邻的两行调换位置,
2,并保存调换位置后的顺序;
解决方案 »
- 每天散1分,天天好心情
- tdbchart 中给曲线设置结点是在哪里设置的
- 50高分请教"没有注册类别"的讨厌问题,请高手解决
- ini文件的一条value值有没有最大长度限制啊?谢谢!
- 请问如何使帖子出现在几个栏目里面呢?
- 安装delphi7了,好多控件没法用呀。谁知道rxlib for delphi7出来了没有,在哪里下载?
- 哪里有mmtools 控件下载啊。
- 如何SQL结果返回到LABEL里面
- 哪位高手能发给我一个在delphi中调用.chm的程序实例,谢谢!
- 求教几个页面打印,打印预览的问题~~~~~~~~~~
- 集思广益,寻求货币数据格式化问题最优解决方案!
- 怎么检测xp的外观为经典windows样式?
i : integer;
s: string;
begin
with aQuery do
begin
if not iDown then
begin
if Not Eof then
begin
i := Fields.Fieldbyname('id').AsInteger;
s := Fields.Fieldbyname(aField).AsString;
Edit;
FieldByName(aField).AsString :=RightStr('0'+inttostr(StrToInt(FieldByName(aField).AsString)+1),2);
Post;
next;
Edit;
FieldByName(aField).AsString := s;
Post;
Sort := 'a';
Locate('id',i,[loCaseInsensitive]);
end;
end
else begin
end;
end;
end;我自己是这样写的,但达不到效果,谢帮忙........
var
id1: integer;
s1: string;
begin
with aQuery do
begin
if not iDown then
begin
if RecNo <> Recordset.RecordCount then
begin
id1 := Fields.Fieldbyname('id').AsInteger;
s1 := Fields.Fieldbyname(aField).AsString;
Edit;
FieldByName(aField).AsString :=RightStr('0' + IntToStr(StrToInt(s1)+1),2);
Post;
Next;
edit;
FieldByName(aField).AsString :=s1;
Post;
//Sort := 'a';
Close;
Open;
Locate('id',id1,[loCaseInsensitive]);
end;
end
else begin
end;
end;
end;--------------------------
现在改成上面这样写,功能是实现了,但每次都CLOSE,OPEN一次DATASET,因为TB的记录较多,所以这样写很慢,
能不能改成不是每次都OPEN啊?
那会是很麻烦的事。有一个想法:
如果表中有五条记录r1, r2, r3, r4, r5
当用户把r2拖到来与r4交换时, 那你就将r2及其后面的记录都删掉。
再插入r4,再插入r3, 再插入r2, 再插入r5。呵呵, 自己也想想都觉得这个方法很变态。楼主就当我没说过吧。
顺便提一下, 理论上讲记录是没有前后顺序的。
你可以在表中再加一个时间列, 记录显示时按时间排序。
当用户要交换记录的位置时, 我们就通过修改时间列的值, 从而下一次显示时,顺序就可以变化了。
顺便提一下, 理论上讲记录是没有前后顺序的。
你可以在表中再加一个时间列, 记录显示时按时间排序。
当用户要交换记录的位置时, 我们就通过修改时间列的值, 从而下一次显示时,顺序就可以变化了。--------------------
RE:
不知你是否看过我上面的写法,其实上面的做法,根据A字段来排序的,当移动相邻两记录时,就相互交换
A值,交换值做起来没有什么麻烦的,现在主要是每次交换完值之后,都CLOSE及OPEN一次DATASET,这样做起来,速度就很慢了(表AB记录多时).