IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Bases de données Delphi Discussion :

Dupliquer un enregistrement complet d'une table paradox


Sujet :

Bases de données Delphi

  1. #1
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    9
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2005
    Messages : 9
    Points : 5
    Points
    5
    Par défaut Dupliquer un enregistrement complet d'une table paradox
    Bonjour,
    je cherche des aides pour copier une fiche d'une table paradox, pour éviter une nouvelle saisie.

    Pour l'instant, j'ai essayé ça comme code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
     
    procedure TForm1.DupliquerFiche;
    var
    i, Numfiche : integer;
    ListeChamps, NomColonne : string;
    begin
    ListeChamps :='';
    NomColonne :='';
    For i:=1 to DM1.QFicheInter.FieldCount -1 do
     
    // je ne le fais pas commencer à 0 pour ne pas prendre le champ autoincrémenté (clé primaire)
     
    if (DM1.QFicheInter.Fields[i].Value <> null) then
    if DM1.QFicheInter.Fields[i].DataType = ftDate then
    begin
    ListeChamps := ListeChamps + ','+ DateToStr(DM1.QFicheInter.Fields[i].Value);
    NomColonne := NomColonne + ','+ DM1.QFicheInter.Fields[i].FieldName;
    end
    else if DM1.QFicheInter.Fields[i].DataType = ftTime then
    begin
    ListeChamps := ListeChamps + ','+ TimeToStr(DM1.QFicheInter.Fields[i].Value);
    NomColonne := NomColonne + ','+ DM1.QFicheInter.Fields[i].FieldName;
    end
    else if DM1.QFicheInter.Fields[i].DataType = ftCurrency then
    begin
    ListeChamps := ListeChamps + ','+ FloatToStr(DM1.QFicheInter.Fields[i].Value);
    NomColonne := NomColonne + ','+ DM1.QFicheInter.Fields[i].FieldName;
    end
    else if DM1.QFicheInter.Fields[i].DataType = ftFloat then
    begin
    ListeChamps := ListeChamps + ','+ FloatToStr(DM1.QFicheInter.Fields[i].Value);
    NomColonne := NomColonne + ','+ DM1.QFicheInter.Fields[i].FieldName;
    end
    else if DM1.QFicheInter.Fields[i].DataType = ftBoolean then
    begin
    ListeChamps := ListeChamps + ','+ BoolToStr(DM1.QFicheInter.Fields[i].Value);
    NomColonne := NomColonne + ','+ DM1.QFicheInter.Fields[i].FieldName;
    end
    else if DM1.QFicheInter.Fields[i].DataType = ftSmallint then
    begin
    ListeChamps := ListeChamps + ','+ IntToStr(DM1.QFicheInter.Fields[i].Value);
    NomColonne := NomColonne + ','+ DM1.QFicheInter.Fields[i].FieldName;
    end
    else if (DM1.QFicheInter.Fields[i].Value <> '') then
    begin
    ListeChamps := ListeChamps + ','+ DM1.QFicheInter.Fields[i].Value;
    NomColonne := NomColonne + ','+ DM1.QFicheInter.Fields[i].FieldName;
    end;
    Delete(Nomcolonne,1,1);
    Delete(ListeChamps,1,1);
    DM1.QFicheInter.SQL.Clear;
    DM1.QFicheInter.SQL.Add('INSERT INTO TFichesInter.DB ('+ NomColonne +')');
    DM1.QFicheInter.SQL.Add('VALUES ('+ ListeChamps +')');
    DM1.QFicheInter.ExecSQL;
    Mon problème est qu'il me dit que j'effectue une utilisation incorrecte du mot clé
    Il me donne la liste des valeurs et VALUES, mais là j'avoue que je sèche.

    Sinon j'ai essayé de la même manière (sans le sql) avec :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    DM1.TFicheInter.InsertRecord([ListeChamps]);
    Là j'ai un problème avec mon premier champ qui est auto incrémenté...

    Si quelqu'un a ne serais-ce qu'un bout d'idée, je prends !!
    Merci

  2. #2
    Modérateur
    Avatar de Rayek
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mars 2005
    Messages
    5 235
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Haute Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2005
    Messages : 5 235
    Points : 8 504
    Points
    8 504
    Par défaut
    Il y a plus simple avec 1 query et 1 TTable :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
    With DM1.QFicheInter do
    begin
      DM1.Table.Append;
      for i := 1 to  FieldCount -1 do
        DM1.Table.Fields.Fields[i].assign(Fields.Fields[i]);
      try
        DM1.Table.Post;
      Except on Exception do
        DM1.Table.Cancel;
      end;
    end; // with
    Attention il faut que les champs de ta requete et de ta table soient dans le même ordre
    sinon il faut ecrire :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    DM1.Table.FieldByName(Fields.Fields[i].DisplayName).assign(Fields.Fields[i]);
    Avec l'une ou l'autre ca copie le champ comme il faut.
    De plus comme ca tu peux meme partir de 0 pour le champs autoincrémenté, il sera pris en compte.

  3. #3
    Modérateur
    Avatar de Rayek
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mars 2005
    Messages
    5 235
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Haute Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2005
    Messages : 5 235
    Points : 8 504
    Points
    8 504
    Par défaut
    Autre petit conseil

    tu peux ecrire ca :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
     
    if (DM1.QFicheInter.Fields[i].Value <> null) then
    if DM1.QFicheInter.Fields[i].DataType = ftDate then
    begin
    ListeChamps := ListeChamps + ','+ DateToStr(DM1.QFicheInter.Fields[i].Value);
    NomColonne := NomColonne + ','+ DM1.QFicheInter.Fields[i].FieldName;
    end
    else if DM1.QFicheInter.Fields[i].DataType = ftTime then
    begin
    ListeChamps := ListeChamps + ','+ TimeToStr(DM1.QFicheInter.Fields[i].Value);
    NomColonne := NomColonne + ','+ DM1.QFicheInter.Fields[i].FieldName;
    end
    else if DM1.QFicheInter.Fields[i].DataType = ftCurrency then
    begin
    ListeChamps := ListeChamps + ','+ FloatToStr(DM1.QFicheInter.Fields[i].Value);
    NomColonne := NomColonne + ','+ DM1.QFicheInter.Fields[i].FieldName;
    end
    else if DM1.QFicheInter.Fields[i].DataType = ftFloat then
    begin
    ListeChamps := ListeChamps + ','+ FloatToStr(DM1.QFicheInter.Fields[i].Value);
    NomColonne := NomColonne + ','+ DM1.QFicheInter.Fields[i].FieldName;
    end
    else if DM1.QFicheInter.Fields[i].DataType = ftBoolean then
    begin
    ListeChamps := ListeChamps + ','+ BoolToStr(DM1.QFicheInter.Fields[i].Value);
    NomColonne := NomColonne + ','+ DM1.QFicheInter.Fields[i].FieldName;
    end
    else if DM1.QFicheInter.Fields[i].DataType = ftSmallint then
    begin
    ListeChamps := ListeChamps + ','+ IntToStr(DM1.QFicheInter.Fields[i].Value);
    NomColonne := NomColonne + ','+ DM1.QFicheInter.Fields[i].FieldName;
    end
    else if (DM1.QFicheInter.Fields[i].Value <> '') then
    begin
    ListeChamps := ListeChamps + ','+ DM1.QFicheInter.Fields[i].Value;
    NomColonne := NomColonne + ','+ DM1.QFicheInter.Fields[i].FieldName;
    end;
    Comme ca

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
     
    if (DM1.QFicheInter.Fields[i].Value <> null) then
    Case DM1.QFicheInter.Fields[i].DataType of
      ftDate:begin
        ListeChamps := ListeChamps + ','+     DateToStr(DM1.QFicheInter.Fields[i].Value);
        NomColonne := NomColonne + ','+ DM1.QFicheInter.Fields[i].FieldName;
      end;
      ftTime: begin
        ListeChamps := ListeChamps + ','+ TimeToStr(DM1.QFicheInter.Fields[i].Value);
        NomColonne := NomColonne + ','+ DM1.QFicheInter.Fields[i].FieldName;
      end;
      ftCurrency,ftFloat  : begin
        ListeChamps := ListeChamps + ','+ FloatToStr(DM1.QFicheInter.Fields[i].Value);
        NomColonne := NomColonne + ','+ DM1.QFicheInter.Fields[i].FieldName;
      end;
      ftBoolean : begin
        ListeChamps := ListeChamps + ','+ BoolToStr(DM1.QFicheInter.Fields[i].Value);
        NomColonne := NomColonne + ','+ DM1.QFicheInter.Fields[i].FieldName;
      end;
      ftSmallint : begin
        ListeChamps := ListeChamps + ','+ IntToStr(DM1.QFicheInter.Fields[i].Value);
        NomColonne := NomColonne + ','+ DM1.QFicheInter.Fields[i].FieldName;
      end;
      else begin
      ListeChamps := ListeChamps + ','+ DM1.QFicheInter.Fields[i].Value;
      NomColonne := NomColonne + ','+ DM1.QFicheInter.Fields[i].FieldName;
      end; 
    end;
    [/code]

  4. #4
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    9
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2005
    Messages : 9
    Points : 5
    Points
    5
    Par défaut super
    Merci beaucoup, j'avais pas réfléchi au case, effectivement c'est mieux.
    J'essaye et je te tiens au courant

    Merci quand même

  5. #5
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    9
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2005
    Messages : 9
    Points : 5
    Points
    5
    Par défaut super
    Double merci, ça marche super.
    C'est génial !!

  6. #6
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    9
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2005
    Messages : 9
    Points : 5
    Points
    5
    Par défaut dupliquer un enregistrement complet : problème
    Bonjour,
    Tout fonctionne sauf qu'il me duplique toujours le même enregistrement !
    J'ai beau essayé différentes choses rien n'y fait.
    Si quelqu'un peut m'aider ?

  7. #7
    Modérateur
    Avatar de Rayek
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mars 2005
    Messages
    5 235
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Haute Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2005
    Messages : 5 235
    Points : 8 504
    Points
    8 504
    Par défaut
    il faut que QFicheInter soit bien positionné sur le bon enregistement si tu veux que ca en duplique d'autres.

    Si tu ouvres qu'une fois ton QFicheInter et que ne fait aucune modification voir de locate dessus, il est normal que tu es toujours la meme fiche de dupliquée.

  8. #8
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    9
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2005
    Messages : 9
    Points : 5
    Points
    5
    Par défaut dupliquer un enregistrement complet
    Je m'en suisdouté c'est pourquoi j'ai essayé cela, même résultat :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
     
    procedure TForm1.DupliquerFiche;
    var                                   //duplique toujours la première fiche
        i : integer;
    begin
        DM1.QFicheInter.First;
        while not DM1.QFicheInter.Eof do
        begin
            if MainForm.NumFiche = DM1.QFicheInter.FieldValues['NUMINTER'] then
            begin
                With DM1.TFicheInter do
                begin
                    try
                        Append;
                        for i := 1 to  FieldCount -1 do
                        begin
                            Fields.Fields[i].assign(DM1.QFicheInter.Fields.Fields[i]);
                        end;
                        Post;
                    Except on E: Exception do
                    begin
                        ShowMessage(E.Message);
                        Cancel;
                    end;
                    end;  // except
                end; // with
                break;
            end
            else
                DM1.QFicheInter.Next;
        end;
    end;
    Je ne vois pas ce qui cloche...

  9. #9
    Modérateur
    Avatar de Rayek
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mars 2005
    Messages
    5 235
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Haute Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2005
    Messages : 5 235
    Points : 8 504
    Points
    8 504
    Par défaut Re: dupliquer un enregistrement complet
    Citation Envoyé par sylvie cl
    Je m'en suisdouté c'est pourquoi j'ai essayé cela, même résultat :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
     
    procedure TForm1.DupliquerFiche;
    var                                   //duplique toujours la première fiche
        i : integer;
    begin
        DM1.QFicheInter.First;
        while not DM1.QFicheInter.Eof do
        begin
            if MainForm.NumFiche = DM1.QFicheInter.FieldValues['NUMINTER'] then
            begin
                With DM1.TFicheInter do
                begin
                    try
                        Append;
                        for i := 1 to  FieldCount -1 do
                        begin
                            Fields.Fields[i].assign(DM1.QFicheInter.Fields.Fields[i]);
                        end;
                        Post;
                    Except on E: Exception do
                    begin
                        ShowMessage(E.Message);
                        Cancel;
                    end;
                    end;  // except
                end; // with
                break;
            end
            else  <--- enleve ca sinon tu parcour jamais ton QficheInter
                DM1.QFicheInter.Next;
        end;
    end;
    Je ne vois pas ce qui cloche...
    Voir la reponse dans le code ^^

  10. #10
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    9
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2005
    Messages : 9
    Points : 5
    Points
    5
    Par défaut dupliquer un enregistrement complet
    Désolée, mais si, si, je le parcours avec ou sans le else (else du if), j'ai fais des pas à pas pour le vérifier.
    Mais ça ne fonctionne toujours pas correctement et pourtant j'ai bien le bon numéro de fiche à dupliquer dans NumFiche

    Je comprends pas

  11. #11
    Modérateur
    Avatar de Rayek
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mars 2005
    Messages
    5 235
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Haute Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2005
    Messages : 5 235
    Points : 8 504
    Points
    8 504
    Par défaut
    Ok, j'avais pas fait gaffe don selon le type de numfiche :

    String :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
     if UpperCase(trim(MainForm.NumFiche)) = uppercase(trim(DM1.QFicheInter.FieldByName('NUMINTER').asstring)) then
    Si c'est un integer :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
     if MainForm.NumFiche = DM1.QFicheInter.FieldByName('NUMINTER').asinteger then
    sinon vu que tu utilises une requete "QFicheInter".
    Pourquoi ne pas faire directement dans ta requete.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
    With QFicheInter do
    begin
      Close;
      SQL.clear;
      SQL.add('select * from LATABLE');
    //  SQL.Add('Where NumInter = ' + QuotedStr(NumFiche)); // si string
    // SQL.Add('Where NumInter = ' + NumFiche); // si integer;
      Open;
    end;
     
    Puis apres tu fais ta boucle de transfert normalement.
    Avec ca tu recupères directement tous les enregistrements ayant NumFiche

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 6
    Dernier message: 07/11/2012, 00h45
  2. additionné des enregistrements dans une table paradox
    Par roubase dans le forum Bases de données
    Réponses: 6
    Dernier message: 27/02/2012, 16h08
  3. Enregistrement dans une table paradox
    Par yendre dans le forum Bases de données
    Réponses: 1
    Dernier message: 23/08/2007, 11h13
  4. URGENT - Nombre d'enregistrements différents dans une table
    Par Jeankiki dans le forum Bases de données
    Réponses: 6
    Dernier message: 11/08/2004, 15h51
  5. Migration d'une table PARADOX
    Par DanielW dans le forum Débuter
    Réponses: 6
    Dernier message: 06/05/2004, 21h52

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo