delete-modify-copy a selected recordset
- From: "Thomas Willms" <th.willms@xxxxxxxxxx>
- Date: 17 Apr 2008 08:33:04 -0700
Hello,
I want to modify, delete and copy selected recordsets.
I have two adotables (1 and 2), I copy from 2 to 1,
delete in 2 and modify in 2.
I found some procedures but I already spent many hours with trials how to do this.
1. I succeeded to copy a recordset but allways only the first. Even if I select the second, it is not copied.
2. I don't get it how to delete a specific recordset: I allways get an error: dataset not open, but I don't see why.
3. I want to select several or all datasets and copy them. Is it possible ?
I want to have a sort of modular construction :
One procedure to copy one recordset, then another selecting all and working with the first. How to select more than one recordset ?
Below my code:
procedure TForm1.CopydatasetbuttonClick(Sender: TObject);
var tblName,fn,fm,fl, s : string; Rset : PAnsichar;n: cardinal;
begin
tblName := Listbox3.items[Listbox3.itemindex];
Form1.ADOTable2.active:=false;
Form1.ADOTable2.TableName:=tblName;
form1.ADOTable2.active:=true; //ValidateDB
Form1.ADOTable1.active:=false;
Form1.ADOTable1.TableName:=tblName;
Form1.ADOTable1.active:=true; //SERVER ODER PROBE DB
Rset := Form1.ADOTable2.ActiveBuffer;
Form1.ADOTable2.GetCurrentRecord(PChar(Rset));
Copycurrentset(tblname,PChar(Rset));
//Form1.ADOTable2.Recordset.AbsolutePosition:=n;
//Form1.ADOTable2.GetCurrentRecord(PChar(Rset));
//Form1.ADOTable2.deleterecords(arcurrent);
end;
procedure Copycurrentset(stcurrTabel:string;stselDataset : PAnsiChar );
var tblName,fn,fm,fl, s,x,y,feldformat1,stfeldinh,w6 : string; i,code : integer; w3 : variant;
wwert : boolean;
begin
try TRY
fl := Form1.ADOtable2.Fields[0].fieldname;
if stcurrTabel = 'referenceauthors' then fl := 'referenceid';
x := Form1.ADOtable2.Fieldbyname(fl).value;/// ???? asstring;
fm := Form1.ADOtable2.Fields[1].fieldname;
if stcurrTabel = 'referenceauthors' then fm := 'name';
y := Form1.ADOtable2.Fieldbyname(fm).value;/// ???? asstring;
if (recordexistenz1(x,fl,y,fm,stcurrTabel) = 0) then ///neuer //Eintrag aus Thereda
begin
Form1.ADOtable1.Last; Form1.ADOtable1.append;
for i:=0 to Form1.ADOtable2.Fields.Count-1 do
begin
fn:= Form1.Adotable2.Fields[i].FieldName;
w3:= Form1.ADOtable2.FieldByName(fn).value;
feldformat1:= Feldformattyp(fn,stcurrTabel);
if (feldformat1 = 'Boolean') then
begin
WWert:= Form1.ADOTable2.FieldbyName(FN).AsBoolean;
Form1.ADOTable1.FieldbyName(FN).AsBoolean:= WWert;
end;
if (feldformat1 = 'DateTime')then
///Form1.AdvStringGrid1.dates[j3,L]
begin
w3 := Form1.ADOTable2.FieldbyName(FN).AsDateTime;
stfeldinh := datetimetoStr(Form1.ADOTable2.FieldbyName(FN).AsDateTime);
Form1.ADOTable1.FieldbyName(FN).AsDateTime:= w3 ;
end;
if (feldformat1 = 'Integer') then
begin w3:= Form1.ADOTable2.FieldbyName(FN).AsInteger; stfeldinh := InttoStr(w3);
Form1.ADOTable1.FieldbyName(FN).AsDateTime:= w3 ;
end;
if (feldformat1 = 'numerisch')then
///Form1.AdvStringGrid1.floats[j3,L]
begin w3:= Form1.ADOTable2.FieldbyName(FN).value;
w6:=floattostr(w3); stfeldinh := w6 ;
Form1.ADOTable1.FieldbyName(FN).value := w3;
end;
if (feldformat1 = 'AutoInc') then begin end;
if (feldformat1 = 'Memo') then
begin
Form1.ADOTable1.FieldbyName(FN).value := Form1.ADOTable2.FieldbyName(FN).value; end;
if (feldformat1 = 'String') then
begin stfeldinh := Form1.ADOTable2.FieldbyName(FN).asstring ;
Form1.ADOTable1.FieldbyName(FN).asstring := stfeldinh ;
end;
end;
Form1.ADOtable1.updaterecord; Form1.ADOtable1.updatebatch;
end;
finally
Form1.ADOTable1.Close;
Form1.ADOTable2.Close;
end;//try
except end;
end;
procedure TForm1.AllsetsbuttonsClick(Sender: TObject);
var stcurrTabel : string;
begin
stcurrTabel := Form1.Listbox3.items[Form1.Listbox3.itemindex];
Form1.ADOTable1.active:=false; Form1.ADOTable1.TableName:=stcurrTabel;
form1.ADOTable1.active:=true; //SERVER ODER PROBE DB
Form1.ADOTable2.active:=false; Form1.ADOTable2.TableName:=stcurrTabel;
Form1.ADOTable2.active:=true; //ValidateDB
Form1.ADOTable2.First;
While not Form1.Adotable2.eof do
begin
Form1.CopydatasetbuttonClick(self);
Form1.ADOtable2.Next;
end;
end;
I use TMS DBadvGrid components.
Thanks very much
Thomas Willms
.
- Prev by Date: Re: Problems with a tringer
- Next by Date: TCPServer & MSSQL & Threads (Newbie Question)
- Previous by thread: Field width
- Next by thread: TCPServer & MSSQL & Threads (Newbie Question)
- Index(es):