Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
2356 connectés 

  FORUM HardWare.fr
  Programmation
  VB/VBA/VBS

  VB6: Command + paramètre

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

VB6: Command + paramètre

n°391646
mario51
Posté le 13-05-2003 à 11:16:07  profilanswer
 

Bonjour
 
J'ai créé une commande contenant une requete sql du genre "Select * from Matable where code= ?"
et j'ai appellé mon parametre parCode.
 
Lorsque j'appelle ma commande, comment je fais pour spécifier la valeur du parametre.
 
(appelle de la commande: dataEnvironnement.maCommande)
 
D'avance merci

mood
Publicité
Posté le 13-05-2003 à 11:16:07  profilanswer
 

n°391669
mario51
Posté le 13-05-2003 à 11:25:37  profilanswer
 

J'ai trouvé:
il faut simplement faire
dataEnvironement.maComande(monParametre)
 
 
Mon pb est maintenant le suivant: le parametre attendu est un String et lorsque je fais maCommande("0001" ) : "Paramatre de type incorrecet ou en conflit avec les autres...."
 
 
une idée ???

n°391672
MagicBuzz
Posté le 13-05-2003 à 11:27:48  profilanswer
 

Essaie déjà avec un champ numérique, histoire d'être sûr.

n°391681
MagicBuzz
Posté le 13-05-2003 à 11:33:23  profilanswer
 

Sinon, la syntaxe, c'est :
 


      .Parameters(strParamName1) = varParamValue1
      .Parameters(strParamName2) = varParamValue2


 
Voilà u exemple complet, utilisant une autre syntaxe :
 


Set Cmd1 = New ADODB.Command
 
Set Cmd1.ActiveConnection = Conn1
 
Cmd1.CommandText = "SELECT * FROM Authors WHERE AU_ID = ?"
 
 
Set Param1 = Cmd1.CreateParameter(, adInteger, adParamInput, 10)
 
Param1.Value = 10
 
Cmd1.Parameters.Append Param1
 
Set Param1 = Nothing
 
 
Set Rs1 = Cmd1.Execute()

n°391690
MagicBuzz
Posté le 13-05-2003 à 11:35:38  profilanswer
 

Le post complet d'où est tiré mon exemple :
 
 
I had to post this again because the HTML got munged the first time...
 
 
OK. There is a Parameters collection associated with the Command  
object. You can also set the command text and command type.
 
 
Set Cmd1 = New ADODB.Command
 
Set Cmd1.ActiveConnection = Conn1
 
Cmd1.CommandText = "SELECT * FROM Authors WHERE AU_ID = ?"
 
 
Set Param1 = Cmd1.CreateParameter(, adInteger, adParamInput, 10)
 
Param1.Value = 10
 
Cmd1.Parameters.Append Param1
 
Set Param1 = Nothing
 
 
Set Rs1 = Cmd1.Execute()
 
 
The '?' in the string represents a parameter. Multiple '?' can be used for multiple parameters. The parameters are applied in the order they are appended, I believe.
 
 
This article:
 
 
http://msdn.microsoft.com/library/ [...] 97/ado.htm
 
 
Describes using the parameters collection pretty completely. Another alternative is to build a string and then execute the string. The problem with this of course is making sure that the data type is represented correctly (for instance, a string with an embedded single quote, how you format dates might be provider dependent).
 
-- Edit : Pour les constantes à passer à createparameter, cherche sur le net leur définition


Message édité par MagicBuzz le 13-05-2003 à 11:38:32
n°391780
mario51
Posté le 13-05-2003 à 12:30:42  profilanswer
 

Merci beaucoup !!!


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  VB/VBA/VBS

  VB6: Command + paramètre

 

Sujets relatifs
Problème de passage de paramètre avec CreateThread[VB6] Yen a qui savent utiliser SHAppBar ? (redimensionner le bureau)
[VB6] Extraire une icone avec extracticon ok, mais comment la sauver ?VB6: datagrid et scroll bar
VB6: Erreur de compilation incompréhensible....pour moiVB6 : recordset
[VB6] Gérer les erreurs globalementVB6 et SQLServer
[VB6] Date environnement et recordset ouvert ou fermé ?[VB6] Comment savoir si une transaction est ouvert ?
Plus de sujets relatifs à : VB6: Command + paramètre


Copyright © 1997-2025 Groupe LDLC (Signaler un contenu illicite / Données personnelles)