select top 100 * from 表名 where id not in (select top page_no*100 * from 表名)page_no是程序中的变量 取数据时分页取 上面是每次取100条的。可以看一下
procedure TmainForm.showdata(ipage: integer;aqStore:TADOQuery); procedure CreadeAdsField; var i: Integer; begin adsClone.Close; adsClone.FieldDefs.Clear; for i := 0 to aqStore.FieldCount - 1 do begin if i = aqStore.FieldCount then Continue; adsClone.FieldDefs.Add(aqStore.Fields[i].FieldName, aqStore.Fields[i].DataType, aqStore.Fields[i].Size); end; adsClone.CreateDataSet; end; var i, j: Integer; rs: adoint.RecordSet; begin pCount := aqStore.Recordset.PageCount; If pCount=0 THEN BEGIN lblCount.Caption :=' ¸ÃÒ³Î޼Ǽ¡£'; ds_ReadHistory.DataSet := aqStore; for i:=0 to dbg_ShowInfo.Columns.Count-1 do dbg_ShowInfo.Columns[i].Visible:=false; dbg_ShowInfo.AutoFitColWidths:=true; EXIT; END; aqStore.Recordset.AbsolutePage := iPage; rs := aqStore.Recordset; CreadeAdsField; adsClone.DisableControls; for i := 0 to rs.PageSize - 1 do begin adsClone.append; for j :=0 to rs.Fields.Count - 1 do adsClone.Fields[j].Value := rs.Fields[j].Value; rs.MoveNext; if rs.EOF then Break; end; adsClone.EnableControls; adsClone.First; ds_ReadHistory.DataSet := adsClone; ds_ReadHistory.DataSet.Active:=TRUE; lblCount.Caption := 'Ò³´Î£º' + IntToStr(iPage) + '/' + IntToStr(pCount); end;
select top 100 * from 表名 where id not in (select top page_no*100 * from 表名)page_no是程序中的变量
取数据时分页取
上面是每次取100条的。可以看一下
procedure CreadeAdsField;
var
i: Integer;
begin
adsClone.Close;
adsClone.FieldDefs.Clear;
for i := 0 to aqStore.FieldCount - 1 do
begin
if i = aqStore.FieldCount then Continue;
adsClone.FieldDefs.Add(aqStore.Fields[i].FieldName, aqStore.Fields[i].DataType, aqStore.Fields[i].Size);
end;
adsClone.CreateDataSet;
end;
var
i, j: Integer;
rs: adoint.RecordSet;
begin
pCount := aqStore.Recordset.PageCount;
If pCount=0 THEN
BEGIN
lblCount.Caption :=' ¸ÃÒ³Î޼Ǽ¡£';
ds_ReadHistory.DataSet := aqStore;
for i:=0 to dbg_ShowInfo.Columns.Count-1 do
dbg_ShowInfo.Columns[i].Visible:=false;
dbg_ShowInfo.AutoFitColWidths:=true;
EXIT;
END;
aqStore.Recordset.AbsolutePage := iPage;
rs := aqStore.Recordset;
CreadeAdsField;
adsClone.DisableControls; for i := 0 to rs.PageSize - 1 do
begin
adsClone.append;
for j :=0 to rs.Fields.Count - 1 do
adsClone.Fields[j].Value := rs.Fields[j].Value;
rs.MoveNext;
if rs.EOF then Break;
end;
adsClone.EnableControls;
adsClone.First;
ds_ReadHistory.DataSet := adsClone;
ds_ReadHistory.DataSet.Active:=TRUE;
lblCount.Caption := 'Ò³´Î£º' + IntToStr(iPage) + '/' + IntToStr(pCount);
end;