PDA

Ver la Versión Completa : insercion en ado


vroa74
27-03-2007, 20:59:02
Hola:
estoy modificando un codigo que me dieron, solo que no tengo la menor idea de que hacer con este codigo.
Para entrar mas en tema le comento.
no se como hace la insecion de los datos y la verdad no tengo idea.
debo insertar datos [integer,string,date,memo,time.]


function miDB.ag_ejemplo(ejemplo: TTejemplo): Integer;
var
mio: TADODataSet;
tptStream: TMemoryStream;
id: Integer;
begin
// get DB data and append one row
mio := TADODataSet.Create(nil);
mio.Connection := connection;
mio.CursorType := ctStatic;
mio.LockType := ltOptimistic;
mio.CommandText := 'SELECT * FROM MyData';
mio.Open();
mio.Append();
tptStream := TMemoryStream.Create();
tptStream.write(template.tpt^, template.size);

(mio.FieldByName('template') as TBlobField).LoadFromStream(tptStream);
//******************************************************
(mio.FieldByName('nombres') as Tstring).????????????????????????????
(mio.FieldByName('apaterno') as Tstring).????????????????????????????
(mio.FieldByName('amaterno') as Tstring).????????????????????????????
(mio.FieldByName('fecha') as Tdate).????????????????????????????
(mio.FieldByName('cp.') as Tinteger).????????????????????????????
(mio.FieldByName('id_control') as Tinteger).????????????????????????????
(mio.FieldByName('nombres') as Tstring).????????????????????????????
//******************************************************
mio.post();
// get the ID of enrolled template.
id := mio.FieldByName('ID').AsInteger;

tptStream.Free();
mio.Close();
mio.Free();
ag_ejemplo := id;
end;

:confused::confused::confused:
Muchas gracias por su ayuda.

vroa74
28-03-2007, 00:13:27
ya solucione mi problema.

Código Delphi [-] (http://www.clubdelphi.com/foros/#)function miDB.ag_ejemplo(ejemplo: TTejemplo): Integer; var mio: TADODataSet; tptStream: TMemoryStream; id: Integer; begin // get DB data and append one row mio := TADODataSet.Create(nil); mio.Connection := connection; mio.CursorType := ctStatic; mio.LockType := ltOptimistic; mio.CommandText := 'SELECT * FROM MyData'; mio.Open(); mio.Append(); tptStream := TMemoryStream.Create(); tptStream.write(template.tpt^, template.size); (mio.FieldByName('template') as TBlobField).LoadFromStream(tptStream); //****************************************************** mio.FieldByName('nombres').AsString := template.Tnombres; mio.FieldByName('apaterno').AsString := template.Tapaterno; mio.FieldByName('amaterno').AsString := template.Tamaterno; mio.FieldByName('fecha').AsDateTime:= template.Tfecha; mio.FieldByName('direccion').AsString := template.Tdireccion; mio.FieldByName('depto').AsString := template.Tdepto; mio.FieldByName('cp').AsInteger := template.TCP; mio.FieldByName('colonia').AsString := template.Tcolonia; mio.FieldByName('nempleado').AsInteger := template.Tnempleado; //****************************************************** mio.post(); // get the ID of enrolled template. id := mio.FieldByName('ID').AsInteger; tptStream.Free(); mio.Close(); mio.Free(); ag_ejemplo := id; end;