Ali_usto
Messages postés131Date d'inscriptionlundi 20 novembre 2006StatutMembreDernière intervention11 octobre 2010
-
24 mai 2007 à 16:37
cs_cantador
Messages postés4720Date d'inscriptiondimanche 26 février 2006StatutModérateurDernière intervention31 juillet 2021
-
26 mai 2007 à 18:42
Salut , je voudrais faire une recherche dans une table personne.db cette recherche se fait par les champs nom et prenom je suis arrivé a faire la recherche a partir d'un seul champ qui est 'nom' par la methode suivante :
procedure TForm1.RechercheClick(Sender: TObject);
var
rech : string;
reslt: boolean ;
begin
rech:= InputBox('Recherche', 'entrer le nom de la personne :', '');
table1.first;
reslt:=false;
while(not table1.eof)do
if table1.FieldValues['NOM']= rech then
begin
reslt:=true;
break;
end
else
table1.next;
if not reslt then
MessageDlg('Enregistrement introuvable dans la table',mtInformation,[mbOk], 0)
end;
je n'ai pas su comment faire la recherche a partir des deux champs nom et prenom , j'ai essayé plusieurs combines mais a chaque fois sa ne marchait pas , pouvez vous m'aider
merci d'avance Ali
cs_Delphiprog
Messages postés4297Date d'inscriptionsamedi 19 janvier 2002StatutMembreDernière intervention 9 janvier 201332 25 mai 2007 à 14:44
Hello,
Pourquoi ne pas, tout simplement, utiliser une requête ?
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Db, DbTables;
type
TRecSearchResult = (srCanceled, srNotFound, srFound);
TForm1 = class (TForm)
Button1: TButton;
Table1: TTable;
procedure Button1Click(Sender: TObject);
private
function Recherche: TRecSearchResult;
end;
var
Form1: TForm1;
implementation
resourcestring
sEnregistrementIntrouvableDansLaT = 'Enregistrement introuvable dans la table';
sEntrerLeNomDeLaPersonne = 'entrer le nom de la personne :';
sEntrerLePrenomDeLaPersonne = 'entrer le prénom de la personne :';
sRecherche = 'Recherche';
{$R *.dfm}
function TForm1.Recherche(): TRecSearchResult;
var
nom, prenom: string;
Q: TQuery;
begin
Result : = srNotFound;
nom := InputBox(sRecherche, sEntrerLeNomDeLaPersonne, '');
prenom := InputBox(sRecherche, sEntrerLePrenomDeLaPersonne, '');
if (nom EmptyStr) <gras>and (prenom</gras> EmptyStr) then
begin
Result := srCanceled;
Exit;
end ;
nom : = QuotedStr(nom);
prenom := QuotedStr(prenom);
Q := TQuery.Create(self);
try
Q.DataBaseName := Table1.DataBaseName; Q.SQL.Text :'SELECT * FROM maTable WHERE nom :nom';
Q.ParamByName('nom').AsString := nom;
if prenom <> EmptyStr then
begin
Q.Sql.Add('AND prenom = :prenom');
Q.ParamByName('prenom').AsString := prenom;
end ;
Q.Open;
if Q.RecordCount > 0then
Result : = srFound;
finally
FreeAndNil(Q);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if Recherche = srNotFound then
MessageDlg(sEnregistrementIntrouvableDansLaT,mtInformation,[mbOk], 0);
end ;
end.
Ce code n'est qu'un exemple simple pour illustrer la méthode préconisée.
May Delphi be with you !
<hr color ="#008000" />
Pensez à cliquer sur Réponse acceptée lorsque la réponse vous convient.
http://www.afipa.net/
cs_guirat
Messages postés10Date d'inscriptiondimanche 26 mars 2006StatutMembreDernière intervention15 juin 2007 25 mai 2007 à 15:17
Bonjour
Utilise une requête
Var ADO:Tadoquery;
ADO:=Tadoquery.creat(Nil);
ADO.ConnectionString:='Nom de la Connexion';
with ADO Do
Begin
Sql.clear;Sql.add('select Nom,Prenom ');
Sql.add('From table1where Nom='+Quotedstr(Nom));
Sql.add('and prenom='+Quotedstr(prenom));
open
End;
If ADO.isempty then
Showmessage('Client N''existe Pas');
Une Aute :
with ADO Do
Begin
Sql.clear;Sql.add('select Nom+''+Prenom as Client ');
Sql.add('From table1where Nom+''+Prenom=');
Sql.add('+Quotedstr(Nom+prenom));
open
End;
If ADO.isempty then
Showmessage('Client N''existe Pas');
Bon Contuniation
Vous n’avez pas trouvé la réponse que vous recherchez ?
dominique.stock
Messages postés436Date d'inscriptionvendredi 7 novembre 2003StatutMembreDernière intervention 8 octobre 20087 24 mai 2007 à 17:15
Bonjour,
S'il n'y a pas d'ndex, effectivement, c'est une façon de procéder.
peut être pas la plus rapide mais si ça marche.
Pour ajouter le prénom dans ta recherche,
if (table1.FieldValues['NOM']= rech) and (table1.FieldValues['PRENOM']=rech2) then ....