从数据库中检索值
与我以前的问题 a>
我在StringGrid中成功将字符串值保存到我的数据库中。
现在,我想从数据库中检索值,并将其从StringGrid中恢复。
这是我尝试的:
procedure TForm1.BitBtn1Click(Sender: TObject);
var i, iRow, iCol: integer ;
s : string;
Grid2: TStringGrid;
strArray : Array of String;
charArray : Array[0..0] of Char;
begin
getRecords;
with SqlQuery4 do
begin
if RecordCount <> 0 then
begin
names := FieldByName('names').AsString;
s := names;
charArray[0] := '|';
strArray := s.Split(charArray);
Grid2 := Form7.StringGrid1;
i := 0;
iCol:= 0;
iRow:=0;
for iRow := 1 to 19 do // increment rows
begin
for iCol := 0 to 5 do // increment cols / max 5 cols
begin
if iCol = 5 then iCol := 0; // reset column so that it will go on next row
for i := 0 to Length(strArray)-1 do // get string one by one
begin
Grid2.RowCount := Grid2.RowCount + 1; // add row
Grid2.Cells[iCol, iRow] := strArray[i]; // this value always overwrite, how to save this previous data?
end;
end;
end;
end;
end;
end;
它添加了行,但没有在数据库中获取值。
In connection with my previous question
I've successfully save string values in StringGrid to my database in one column.
Now I want to retrieved the values from database and put it back from StringGrid.
This is what I've tried :
procedure TForm1.BitBtn1Click(Sender: TObject);
var i, iRow, iCol: integer ;
s : string;
Grid2: TStringGrid;
strArray : Array of String;
charArray : Array[0..0] of Char;
begin
getRecords;
with SqlQuery4 do
begin
if RecordCount <> 0 then
begin
names := FieldByName('names').AsString;
s := names;
charArray[0] := '|';
strArray := s.Split(charArray);
Grid2 := Form7.StringGrid1;
i := 0;
iCol:= 0;
iRow:=0;
for iRow := 1 to 19 do // increment rows
begin
for iCol := 0 to 5 do // increment cols / max 5 cols
begin
if iCol = 5 then iCol := 0; // reset column so that it will go on next row
for i := 0 to Length(strArray)-1 do // get string one by one
begin
Grid2.RowCount := Grid2.RowCount + 1; // add row
Grid2.Cells[iCol, iRow] := strArray[i]; // this value always overwrite, how to save this previous data?
end;
end;
end;
end;
end;
end;
It adds row but doesn't get the values in database..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您缺少 first 和下一个在查询对象的 tdataset 中移动的方法/em>
此代码可以工作:
当您使用SQL查询打开一组行(Delphi中的数据集)时的基本方法是这样:
You are missing the First and Next methods for moving in a TDataSet of the query object SqlQuery4
This code could work:
The basic way when you open a set of rows (a data set in Delphi) using a SQL query is something like this: