晚上睡不着,帮你把这段代码给写了.希望对你有帮助 procedure TForm1.FormShow(Sender: TObject); begin ADOQuery1.Close; ADOQuery1.SQL.Text := 'select * from sysobjects where xtype = ''u'''; ADOQuery1.Open; while not ADOQuery1.Eof do begin ListBox1.Items.Add(ADOQuery1.fieldbyname('name').AsString); ADOQuery1.Next; end; ADOQuery1.Close; end;procedure TForm1.ListBox1Click(Sender: TObject); var i,j : integer; begin if ListBox1.ItemIndex >= 0 then begin ADOQuery1.Close; ADOQuery1.SQL.Text := 'select * from ' + ListBox1.Items[ListBox1.itemindex]; ADOQuery1.Open; if ADOQuery1.RecordCount > 0 then begin StringGrid1.colCount := ADOQuery1.FieldCount; StringGrid1.RowCount := ADOQuery1.RecordCount + 1; for i := 0 to ADOQuery1.FieldCount -1 do StringGrid1.Cells[i,0] := ADOQuery1.Fields[i].DisplayName; i := 1; while not ADOQuery1.Eof do begin for j := 0 to ADOQuery1.FieldCount -1 do StringGrid1.Cells[j,i] := ADOQuery1.Fields[j].AsString; Inc(i); ADOQuery1.Next; end; end; ADOQuery1.Close; end; end;
procedure TForm1.FormShow(Sender: TObject);
begin
ADOQuery1.Close;
ADOQuery1.SQL.Text := 'select * from sysobjects where xtype = ''u''';
ADOQuery1.Open;
while not ADOQuery1.Eof do
begin
ListBox1.Items.Add(ADOQuery1.fieldbyname('name').AsString);
ADOQuery1.Next;
end;
ADOQuery1.Close;
end;procedure TForm1.ListBox1Click(Sender: TObject);
var
i,j : integer;
begin
if ListBox1.ItemIndex >= 0 then
begin
ADOQuery1.Close;
ADOQuery1.SQL.Text := 'select * from ' + ListBox1.Items[ListBox1.itemindex];
ADOQuery1.Open;
if ADOQuery1.RecordCount > 0 then
begin
StringGrid1.colCount := ADOQuery1.FieldCount;
StringGrid1.RowCount := ADOQuery1.RecordCount + 1;
for i := 0 to ADOQuery1.FieldCount -1 do
StringGrid1.Cells[i,0] := ADOQuery1.Fields[i].DisplayName;
i := 1;
while not ADOQuery1.Eof do
begin
for j := 0 to ADOQuery1.FieldCount -1 do
StringGrid1.Cells[j,i] := ADOQuery1.Fields[j].AsString;
Inc(i);
ADOQuery1.Next;
end;
end;
ADOQuery1.Close;
end;
end;