Ir al contenido


Foto

Problema con migración DBF a Access


  • Por favor identifícate para responder
2 respuestas en este tema

#1 enecumene

enecumene

    Webmaster

  • Administrador
  • 7.419 mensajes
  • LocationRepública Dominicana

Escrito 31 julio 2009 - 06:39

Pues eso tengo un problema migrando una BD desde DBF a Access, tengo el siguiente code:



delphi
  1. procedure TFImport.btnImportarClick(Sender: TObject);
  2. begin
  3. {*** DESHABILITAMOS LOS BOTONES PARA EVITAR VOLVER PRESIONAR MIENTRAS CORRE EL PROCESO ***}
  4. btnImportar.Enabled := False;
  5. btnCerrar.Enabled := False;
  6.  
  7. {*** SI LA TABLA NO ESTA ABIERTA PUES DEBEMOS ABRIRLO ***}
  8. if not DM.dbfEmpleados.Active then
  9.   DM.dbfEmpleados.Open;
  10.  
  11. PB.Max := DM.dbfEmpleados.RecordCount;
  12.  
  13. DM.dbfEmpleados.First;
  14. While not DM.dbfEmpleados.Eof do begin
  15.  
  16.   {*** VERIFICAMOS SI EXISTE EN LA BD ***}
  17.   DM.QImpExiste.Close;
  18.   DM.QImpExiste.Parameters.ParamByName('ECode').Value := DM.dbfEmpleados.fieldbyname('code').AsString;
  19.   DM.QImpExiste.Open;
  20.   if DM.QImpExiste.RecordCount > 0 then begin //SI HAY UNA COINCIDENCIA
  21.  
  22.     {*** PROCEDEMOS ACTUALIZAR EL DATO EXISTENTE ***}
  23.     DM.QUpdate.Parameters.ParamByName('ENombre').Value := DM.dbfEmpleados.FieldByName('name').AsString;
  24.     DM.QUpdate.Parameters.ParamByName('EApellido').Value := DM.dbfEmpleados.FieldByName('lastname').AsString;
  25.     DM.QUpdate.Parameters.ParamByName('EDpto').Value := DM.dbfEmpleados.FieldByName('cdepart').AsString;
  26.     DM.QUpdate.Parameters.ParamByName('ECargo').Value := DM.dbfEmpleados.FieldByName('codpos').AsString;
  27.     DM.QUpdate.Parameters.ParamByName('ETurno').Value := DM.dbfEmpleados.FieldByName('shift1').AsString;
  28.     DM.QUpdate.ExecSQL;
  29.     CUpdated := CUpdated + 1; //sumamos uno si es actualizado
  30.     PB.StepIt;
  31.     lbUpdated.Caption := IntToStr(CUpdated);
  32.   end else begin
  33.  
  34.     {*** DE LO CONTRARIO INSERTAMOS UNO NUEVO ***}
  35.     DM.QImport.Parameters.ParamByName('ECode').Value := DM.dbfEmpleados.FieldByName('code').AsString;
  36.     DM.QImport.Parameters.ParamByName('ENombre').Value := DM.dbfEmpleados.FieldByName('name').AsString;
  37.     DM.QImport.Parameters.ParamByName('EApellido').Value := DM.dbfEmpleados.FieldByName('lastname').AsString;
  38.     DM.QImport.Parameters.ParamByName('EDptoID').Value := DM.dbfEmpleados.FieldByName('cdepart').AsString;
  39.     DM.QImport.Parameters.ParamByName('ECargo').Value := DM.dbfEmpleados.FieldByName('codpos').AsString;
  40.     DM.QImport.Parameters.ParamByName('ETurno').Value := DM.dbfEmpleados.FieldByName('shift1').AsString;
  41.     DM.QImport.ExecSQL;
  42.     CNew := CNew + 1; //sumamos uno si es nuevo
  43.     PB.StepIt;
  44.     lbNew.Caption := IntToStr(CNew);
  45.   end;
  46.   lbDato.Caption := '('+DM.dbfEmpleados.FieldByName('code').AsString+') - '+DM.dbfEmpleados.FieldByName('lastname').AsString+','+DM.dbfEmpleados.FieldByName('name').AsString;
  47.   DM.dbfEmpleados.Next;
  48.   Application.ProcessMessages;
  49. end;
  50. DM.dbfEmpleados.Close;
  51. ShowMessage('¡PROCESO COMPLETADO!');
  52. btnCerrar.Enabled := True;
  53. end;



El resultado es el siguiente:

Imagen Enviada


Como pueden ver los campos Nombre, Apellido, DptoID, Cargo y Turno se repiten el mismo valor, en cambio el campo Codigo si hace la importación correcta, de 7,350 registros se repiten esos valores en los campos mencionados en los primeros 6,848 registros, luego de ahí­ ya cambia, ¿qué podrí­a estar pasando?.

Saludos.
  • 0

#2 Wilson

Wilson

    Advanced Member

  • Moderadores
  • PipPipPip
  • 2.137 mensajes

Escrito 31 julio 2009 - 08:48

Amigo si la clave principal de las tablas en cuestión es 'Code' , en la rutina de actualización no veo que lo estés pasando como parámetro para saber que registros son los que hay que actualizar y por lo tanto se actualizan (todos los campos con excepción del  Code) en  todos los registros existentes.

La sentencia de actualización deberí­a parecerse a esto



sql
  1. UPDATE EMPLEADOS
  2. SET  NAME = :NAME, LASTNAME = :LASTNAME,CDPART = :CDPART,
  3. CODPOS = :CODPOS, SHIFT1 = :SHIFT1
  4. WHERE CODE = :ECODE



y a la rutina de actualización agregar esta lí­nea


delphi
  1. {*** PROCEDEMOS ACTUALIZAR EL DATO EXISTENTE ***} 
  2. DM.QUpdate.Parameters.ParamByName('ECode').Value := DM.dbfEmpleados.FieldByName('Code').AsString; // Agregar esta lí­nea
  3. DM.QUpdate.Parameters.ParamByName('ENombre').Value := DM.dbfEmpleados.FieldByName('name').AsString;   
  4. DM.QUpdate.Parameters.ParamByName('EApellido').Value := DM.dbfEmpleados.FieldByName('lastname').AsString;   
  5. DM.QUpdate.Parameters.ParamByName('EDpto').Value := DM.dbfEmpleados.FieldByName('cdepart').AsString;
  6.  
  7. .........


  • 0

#3 enecumene

enecumene

    Webmaster

  • Administrador
  • 7.419 mensajes
  • LocationRepública Dominicana

Escrito 01 agosto 2009 - 08:34

Ah Vaya, tení­as razón Wilson, se me pasó colocar el where en la consulta, con eso me resolvió el problema, muchas gracias amigo (y).

Saludos.
  • 0




IP.Board spam blocked by CleanTalk.