如果你就是在dbgrid显示的时候显示一个自增的字段的话还可以
oncelldraw的事件中
begin
if Column.Index = 0 then
with DBGrid1.Canvas do
begin
FillRect(Rect);
if DBGrid1.DataSource.DataSet.RecNo <> -1 then
TextOut(Rect.Left + 2, Rect.Top + 2, IntToStr(DBGrid1.DataSource.DataSet.RecNo));
end;
IF object_id('Tempdb..#aa') IS not NULL begin drop table #aa end
SELECT IDENTITY (int, 1, 1) AS a, *
INTO #aa
FROM table
endif
select * from #aa
这样的话就在临时表#aa中有了新的自动累加字段