C
crystal_bobo
Unregistered / Unconfirmed
GUEST, unregistred user!
我想用StringGrid来显示数据库中的内容,但是出了错误:
我放置了一个ADOConnection组件,连接好了Tiyuzu数据库
然后放置一个ADOQuery数据库,连接上ADOConnection,并在ADOQuery的SQL上写上:select * from nan_one
放置一个StringGrid,代码:
procedure TForm1.StringGrid1Click(Sender: TObject);
begin
with ADoQuery1 do
begin
Close;
Sql.Clear;
Sql.add('Select * from nan_one');
open;
TstringGrid1.RowCount := ADoQuery1.RecordSet.count;
TstringGrid1.ColCount := ADoQuery1.Fields.Count;
j := 0;
while not eof do
begin
for i := 0 to TstringGrid1.ColCount-1 do
begin
TstringGrid1.Cells[i,j] := Fields.asstring;
end;
inc(J);
ADoQuery1.next;
end;
end;
end;
显示出了很多的错误
请帮忙看看,怎么改过来呢?
[Error] Unit1.pas(36): Undeclared identifier: 'TstringGrid1'
[Error] Unit1.pas(36): Missing operator or semicolon
[Error] Unit1.pas(36): Undeclared identifier: 'count'
[Error] Unit1.pas(37): Missing operator or semicolon
[Error] Unit1.pas(38): Undeclared identifier: 'j'
[Error] Unit1.pas(41): Undeclared identifier: 'i'
[Error] Unit1.pas(41): 'DO' expected but identifier 'ColCount' found
[Error] Unit1.pas(43): Missing operator or semicolon
[Fatal Error] Project2.dpr(5): Could not compile used unit 'Unit1.pas'
请帮帮忙,初次接触ADOQuery和StringGrid的使用
我放置了一个ADOConnection组件,连接好了Tiyuzu数据库
然后放置一个ADOQuery数据库,连接上ADOConnection,并在ADOQuery的SQL上写上:select * from nan_one
放置一个StringGrid,代码:
procedure TForm1.StringGrid1Click(Sender: TObject);
begin
with ADoQuery1 do
begin
Close;
Sql.Clear;
Sql.add('Select * from nan_one');
open;
TstringGrid1.RowCount := ADoQuery1.RecordSet.count;
TstringGrid1.ColCount := ADoQuery1.Fields.Count;
j := 0;
while not eof do
begin
for i := 0 to TstringGrid1.ColCount-1 do
begin
TstringGrid1.Cells[i,j] := Fields.asstring;
end;
inc(J);
ADoQuery1.next;
end;
end;
end;
显示出了很多的错误
请帮忙看看,怎么改过来呢?
[Error] Unit1.pas(36): Undeclared identifier: 'TstringGrid1'
[Error] Unit1.pas(36): Missing operator or semicolon
[Error] Unit1.pas(36): Undeclared identifier: 'count'
[Error] Unit1.pas(37): Missing operator or semicolon
[Error] Unit1.pas(38): Undeclared identifier: 'j'
[Error] Unit1.pas(41): Undeclared identifier: 'i'
[Error] Unit1.pas(41): 'DO' expected but identifier 'ColCount' found
[Error] Unit1.pas(43): Missing operator or semicolon
[Fatal Error] Project2.dpr(5): Could not compile used unit 'Unit1.pas'
请帮帮忙,初次接触ADOQuery和StringGrid的使用