Copying from grid to Adotable
- From: "Thomas Willms" <thomas.willms@xxxxxx>
- Date: 18 Oct 2007 02:32:19 -0700
Hello,
I am using the procedure below to copy data from a stringgrid (beginning with the column (2fixed +) i3, line variable Min2) to an ACCESS Database (shown in a DBGrid).
1. I never did this before and I have some problems and I am not sure
about the sense of Updatebatch and especially updaterecord because
'updaterecord' didn't update the dataset when used alone.
Another special problem is that I am copying strings and in the
database the format is sometimes DateTime, boolean ,
numeric or currencey.
In this case he refuses to copy saying it is not possible to convert.
I have problems to adapt the copying process to the format and
sometimes it seems that it doesn't work:
procedure AbspeichernSET(i3,Min2:Integer) ;
var j3,k : integer; tabellenname2, FN ,dateiname2, dateiname, resultat,iw: String;
begin
j3:= 0;
Form1.ADOTable2.Append;
While (j3 < Form1.DBAdvGrid1.colcount) do
begin
FN:= Form1.DBAdvGrid1.Cells[j3,0];
if not (FN = 'DBDateTime') then
begin
try
Form1.ADOTable2.FieldbyName(FN).asString:=Form3.AdvStringGrid1.Cells[2+i3,Min2 + j3];
except
try
Form1.ADOTable2.FieldbyName(FN).value:=Form3.AdvStringGrid1.Cells[2+i3,Min2 + j3];
except end;
end;
end;
j3:=j3+1;
end;
Form1.ADOTable2.UpdateRecord;Form1.ADOTable2.UpdateBatch; Form1.ADOTable2.UpdateCursorPos;
end;
In another case I am doing the same from a DBGrid1 (showing data retrieved from Internet PostgreSQL) to a DBGrid2 (in an ADOTable).
54 little tables work well but 3 big tables not:
In one case nothing is copied (because of an error at the end of the
first line although it works in all other cases) , in the two other cases only the last 8 or ten entries are appearing. After these entries it is flickering very much without anything more added at the end....
As I am copying a lot of tables, I change each time the tablename to load the new table from the database and to copy afterwards the data to the Accessfile. I found that it takes much time inthese cases
but I suppose that the loading should be finished before the copying begins..
The code doing the copying is the following
ADOTable1.Active:=false;ADOTable1.TableName:=tabelleNrX;
ADOTable1.Active:=true;
j:= 0;
Form1.ADOTable1.first;
while (j < Frm_SQL_Query.DBAdvGrid1.rowCount-1 ) do
begin
Form1.ADOTable1.last; Form1.ADOTable1.Append;
SpAnzahl:=Frm_SQL_Query.DBAdvGrid1.ColCount-1 ;
For f:= 0 to SpAnzahl do
begin
fn:=Frm_SQL_Query.DBAdvGrid1.cells[f,0]; //Showmessage(FN);
w:=Frm_SQL_Query.DBAdvGrid1.cells[f,1+j]; //Showmessage(w);
Form1.ADOTable1.FieldbyName(FN).AsString:=w;
Form1.DBAdvGrid2.AutoSizeColumns(true,j);
end;
Form1.ADOTable1.Post; Form1.ADOTable1.UpdateBatch;
Form1.ADOTable1.FindLast ; Form1.ADOTable1.UpdateCursorPos;
j:=j+1;
Do you need other info ? Can you help me ? Any ideas to improve; What makes more sense : putting FindFirst, First, Last, FindLast, Insert ?
Does "Append" not simply mean to put it at the end ???
Thanks very much
Thomas Willms
.
- Follow-Ups:
- Re: Copying from grid to Adotable
- From: yannis
- Re: Copying from grid to Adotable
- Prev by Date: Master-detail: I see all the detail records if I append a detail record
- Next by Date: Re: Copying from grid to Adotable
- Previous by thread: Master-detail: I see all the detail records if I append a detail record
- Next by thread: Re: Copying from grid to Adotable
- Index(es):