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

  1. #1
    Membre actif
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    661
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Juin 2006
    Messages : 661
    Points : 244
    Points
    244
    Par défaut Problème avec un SqlSataSource pour alimenter un GridView en prenant en paramètre la valeur d'une dropdownlist
    Bonjour,

    Je suis en auto apprentissage: asp.net + data, j'ai donc une webForm.aspx avec:

    Un SqlDataSource qui alimente une DropDownList:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
    ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" 
    SelectCommand="SELECT &quot;DESCRIPTION_PROFIL&quot; FROM &quot;TBL_PROFIL&quot;"></asp:SqlDataSource>
    Un deuxième SqlDataSource qui alimente un GridView en prenant en paramètre un OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged1" ==> le problème est ici

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" 
                SelectCommand="SELECT &quot;NOM&quot;, &quot;PRENOM&quot;, &quot;DESCRIPTION_PROFIL&quot;, &quot;PROFIL&quot; FROM &quot;VUE_RECRUTEMENT&quot; WHERE (&quot;DESCRIPTION_PROFIL&quot; = ?)" OnSelecting="SqlDataSource2_Selecting"> OnSelecting="SqlDataSource2_Selecting">
                <SelectParameters>
                    <asp:ControlParameter ControlID="DropDownList1" Name="DESCRIPTION_PROFIL" PropertyName="SelectedValue" Type="String" />
                </SelectParameters>
            </asp:SqlDataSource>
    Nom : 1.png
Affichages : 89
Taille : 128,0 Ko

    Quand j’exécute le projet j'ai une erreur: ORA-00911: caractère non valide à cause du ? que me génère l'assistant de mon SqlDataSource

    Mais si force un paramètre directement:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    SelectCommand="SELECT NOM, PRENOM, DESCRIPTION_PROFIL, PROFIL FROM VUE_RECRUTEMENT WHERE DESCRIPTION_PROFIL = 'Informaticien'"
    ==> ça fonctionne

    Comment faire pour mettre le contrôle DropDownList en paramètre dans mon SelectCommand ?

    Code complet:
    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
     
    <body>
        <form id="form1" runat="server">
        <div>
     
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand="SELECT &quot;DESCRIPTION_PROFIL&quot; FROM &quot;TBL_PROFIL&quot;"></asp:SqlDataSource>
            <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="DESCRIPTION_PROFIL" DataValueField="DESCRIPTION_PROFIL" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged1">
            </asp:DropDownList>
            <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" 
                SelectCommand="SELECT &quot;NOM&quot;, &quot;PRENOM&quot;, &quot;DESCRIPTION_PROFIL&quot;, &quot;PROFIL&quot; FROM &quot;VUE_RECRUTEMENT&quot; WHERE (&quot;DESCRIPTION_PROFIL&quot; = ?)" OnSelecting="SqlDataSource2_Selecting">
                <SelectParameters>
                    <asp:ControlParameter ControlID="DropDownList1" Name="DESCRIPTION_PROFIL" PropertyName="SelectedValue" Type="String" />
                </SelectParameters>
            </asp:SqlDataSource>
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3" DataSourceID="SqlDataSource2" AllowPaging="True" AllowSorting="True">
                <Columns>
                    <asp:CommandField ShowSelectButton="True" />
                    <asp:BoundField DataField="NOM" HeaderText="NOM" SortExpression="NOM" />
                    <asp:BoundField DataField="PRENOM" HeaderText="PRENOM" SortExpression="PRENOM" />
                    <asp:BoundField DataField="DESCRIPTION_PROFIL" HeaderText="DESCRIPTION_PROFIL" SortExpression="DESCRIPTION_PROFIL" />
                    <asp:BoundField DataField="PROFIL" HeaderText="PROFIL" SortExpression="PROFIL" />
                </Columns>
                <FooterStyle BackColor="White" ForeColor="#000066" />
                <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
                <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
                <RowStyle ForeColor="#000066" />
                <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
                <SortedAscendingCellStyle BackColor="#F1F1F1" />
                <SortedAscendingHeaderStyle BackColor="#007DBB" />
                <SortedDescendingCellStyle BackColor="#CAC9C9" />
                <SortedDescendingHeaderStyle BackColor="#00547E" />
            </asp:GridView>
     
        </div>
        </form>
    </body>
    D'avance merci

  2. #2
    Membre actif
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    661
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Juin 2006
    Messages : 661
    Points : 244
    Points
    244
    Par défaut
    Bonjour,

    J'ai toujours pas de réponse, je pensais que c'était une question simple pour les habituer de cette technologie.

    Est-ce que je dois reformuler ma question où autre choses ???

    Merci de m'aider .

  3. #3
    Membre expert Avatar de jopopmk
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mars 2011
    Messages
    1 856
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

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

    Informations forums :
    Inscription : Mars 2011
    Messages : 1 856
    Points : 3 570
    Points
    3 570
    Par défaut
    Salut,

    essaie de nommer ton paramètre dans ta seconde requête ("SELECT TRUC, MUCH FROM LABAS WHERE BIDULE = @mon_param")
    Ensuite dans ton SelectParameter positionne l'attribut "name" sur "mon_param".

    Et non, je n'ai jamais utilisé cette méthode, j'ai juste demandé à la MSDN (cf. ce lien)
    Plus je connais de langages, plus j'aime le C.

  4. #4
    Membre actif
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    661
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Juin 2006
    Messages : 661
    Points : 244
    Points
    244
    Par défaut
    Merci de ton aide jopopmk, mais j'avais déjà essayé sans résultat:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" 
                SelectCommand="SELECT NOM, PRENOM, DESCRIPTION_PROFIL, PROFIL FROM VUE_RECRUTEMENT WHERE DESCRIPTION_PROFIL = @DESCRIPTION_PROFIL2" OnSelecting="SqlDataSource2_Selecting">
                <SelectParameters>
                    <asp:ControlParameter ControlID="DropDownList1" Name="DESCRIPTION_PROFIL2" PropertyName="SelectedValue" Type="String" />
                </SelectParameters>
            </asp:SqlDataSource>
    Il me met une erreur ORA-00936: expression absente, il ne me prend pas la requête comme une requête paramétrée ...........

    As-tu une autre idée

  5. #5
    Membre actif
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    661
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Juin 2006
    Messages : 661
    Points : 244
    Points
    244
    Par défaut
    Bonjour,

    Je viens de trouver avec oracle il faut utiliser symbole ":" pour les paramètres

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    ... WHERE ([DESCRIPTION_PROFIL] = :DESCRIPTION_PROFIL)

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

Discussions similaires

  1. Réponses: 10
    Dernier message: 08/07/2006, 12h12
  2. [MySQL] problème avec 2 requetes pour 1 même tableau
    Par guy2004 dans le forum PHP & Base de données
    Réponses: 8
    Dernier message: 03/11/2005, 13h50
  3. Réponses: 2
    Dernier message: 17/10/2005, 23h16
  4. problèmes avec "include file" pour une page asp
    Par chipsense dans le forum ASP
    Réponses: 1
    Dernier message: 02/09/2005, 16h22
  5. [tomcat] [jsp] Problème avec driver OCI pour oracle
    Par nanardcompanie dans le forum Tomcat et TomEE
    Réponses: 3
    Dernier message: 01/07/2004, 10h54

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