首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

数据排序及插入有关问题

2012-03-09 
数据排序及插入问题access数据库中一个表字段:姓名   张三   王五   李四   赵六我要在这个表中插入记录,

数据排序及插入问题
access数据库中一个表
字段:姓名
   张三
   王五
   李四
   赵六
我要在这个表中插入记录,可是总是加到最后,我想可以随便插到我想插入的地方。
另外用户可以调整人名的位置。
怎么做呀?

[解决办法]
晕,这是什么问题
[解决办法]
数表中添一个字段,记录每个人的位置,即顺序ID。
更改人的位置同时更新顺序ID
显示的时候按这个ID排序
[解决办法]
access数据库中有插入数据功能.
[解决办法]
//本例中hh2是表名,name是字段
//让AValue2排在AValue1后面,其中AValue2是要插入的名字
//AValue1是你要排序时AValue2前面的名字
//其中ADOQuery1.connection := ADOConnection1;
//ADOQuery2.connection := ADOConnection1;
函数如下:
procedure order(AValue1,AValue2:string);
var
strsql,InsertSql:string;
begin
strsql := 'select name from hh2 where name = ' + #39 + AValue2 + #39;
ADOQuery2.Close;
ADOQuery2.SQL.Text := strsql;
ADOQuery2.Open;
if ADOQuery2.RecordCount > 0 then//已经存在这个名字了,退出
begin
ShowMessage( '数据库中已经存在这个名字了 ');
Exit;
end;
InsertSql := 'Insert Into hh2(name) values( ' + #39 + AValue2 + #39 + ') ' ;
ADOConnection1.Execute(InsertSql);

strsql := 'SELECT name FROM hh2 order by IIf(name= ' + #39 + AValue1 + #39
+ ',1,IIf(name= ' + #39 + AValue + #39 + ',2,3)) ';
ADOQuery1.Close;
ADOQuery1.SQL.Text := strsql;
ADOQuery1.Open;
ADOQuery1.Locate( 'name ',AValue2,[]);

end;

调用:order( '李四 ', '黄八 ');
显示结果:
李四
黄八
张三
   王五
   赵六

热点排行