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

ASP.NET Discussion :

Problème au DataBind() sur un GridView après ajout de SelectParameters.


Sujet :

ASP.NET

  1. #1
    Candidat au Club
    Profil pro
    Inscrit en
    Février 2008
    Messages
    2
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Février 2008
    Messages : 2
    Points : 2
    Points
    2
    Par défaut Problème au DataBind() sur un GridView après ajout de SelectParameters.
    Bonjour,

    Je fais appel à votre bon coeur car je me casse en ce moment les dents sur un appel à GetData() dans une GridView, via DataBind().

    Commençons par le commencement. J'ai une stored procedure toute bête sur SQL Server, qui admet 8 paramètres...
    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
     
    	create procedure dbo.sp_SelectHist 
    		@idMin bigint,
    		@idMax bigint,
    		@loadingDateStart datetime,
    		@loadingDateEnd datetime,
    		@pageName varchar(100),
    		@language varchar(2),
    		@ip varchar(20),
    		@userAgent varchar(255)
    	as
    	begin
    		select 
    			id,
    			loadingDate,
    			unloadingDate,
    			datediff(second,loadingDate,unloadingDate) as "time",
    			pageName,
    			ip,
    			language,
    			userAgent,
    			logon
    		from dbo.hist
    		where id                  >=   IsNull(@idMin, id)
    		and id                    <=   IsNull(@idMax, id)
    		and loadingDate           >=   IsNull(@loadingDateStart, loadingDate)
    		and loadingDate           <=   IsNull(@loadingDateStart, loadingDate)
    		and IsNull(pageName,'')   like IsNull(@pageName, '%')
    		and IsNull(ip, '')        like IsNull(@ip, '%')
    		and IsNull(userAgent, '') like IsNull(@userAgent, '%')
    		and language              =    IsNull(@language, language);
    	end
    ... et qui fonctionne :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    	execute dbo.sp_SelectHist null,null,null,null,null,null,null,null;
    me sort bien la totalité des rows contenus dans la table.

    Cette stored procedure est utilisée comme SelectCommand dans un TableAdapter généré par VisualStudio. Si je regarde le tag <SelectCommand>, j'ai ceci :
    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
     
                    <SelectCommand>
                      <DbCommand CommandType="StoredProcedure" ModifiedByUser="False">
                        <CommandText>dbo.sp_SelectHist</CommandText>
                        <Parameters>
                          <Parameter AllowDbNull="True" AutogeneratedName="" DataSourceName="" DbType="Int32" Direction="ReturnValue" ParameterName="@RETURN_VALUE" Precision="10" ProviderType="Int" Scale="0" Size="4" SourceColumnNullMapping="False" SourceVersion="Current">
                          </Parameter>
                          <Parameter AllowDbNull="True" AutogeneratedName="" DataSourceName="" DbType="Int64" Direction="Input" ParameterName="@idMin" Precision="19" ProviderType="BigInt" Scale="0" Size="8" SourceColumnNullMapping="False" SourceVersion="Current">
                          </Parameter>
                          <Parameter AllowDbNull="True" AutogeneratedName="" DataSourceName="" DbType="Int64" Direction="Input" ParameterName="@idMax" Precision="19" ProviderType="BigInt" Scale="0" Size="8" SourceColumnNullMapping="False" SourceVersion="Current">
                          </Parameter>
                          <Parameter AllowDbNull="True" AutogeneratedName="" DataSourceName="" DbType="DateTime" Direction="Input" ParameterName="@loadingDateStart" Precision="23" ProviderType="DateTime" Scale="3" Size="8" SourceColumnNullMapping="False" SourceVersion="Current">
                          </Parameter>
                          <Parameter AllowDbNull="True" AutogeneratedName="" DataSourceName="" DbType="DateTime" Direction="Input" ParameterName="@loadingDateEnd" Precision="23" ProviderType="DateTime" Scale="3" Size="8" SourceColumnNullMapping="False" SourceVersion="Current">
                          </Parameter>
                          <Parameter AllowDbNull="True" AutogeneratedName="" DataSourceName="" DbType="AnsiString" Direction="Input" ParameterName="@pageName" Precision="0" ProviderType="VarChar" Scale="0" Size="100" SourceColumnNullMapping="False" SourceVersion="Current">
                          </Parameter>
                          <Parameter AllowDbNull="True" AutogeneratedName="" DataSourceName="" DbType="AnsiString" Direction="Input" ParameterName="@language" Precision="0" ProviderType="VarChar" Scale="0" Size="2" SourceColumnNullMapping="False" SourceVersion="Current">
                          </Parameter>
                          <Parameter AllowDbNull="True" AutogeneratedName="" DataSourceName="" DbType="AnsiString" Direction="Input" ParameterName="@ip" Precision="0" ProviderType="VarChar" Scale="0" Size="20" SourceColumnNullMapping="False" SourceVersion="Current">
                          </Parameter>
                          <Parameter AllowDbNull="True" AutogeneratedName="" DataSourceName="" DbType="AnsiString" Direction="Input" ParameterName="@userAgent" Precision="0" ProviderType="VarChar" Scale="0" Size="255" SourceColumnNullMapping="False" SourceVersion="Current">
                          </Parameter>
                        </Parameters>
                      </DbCommand>
                    </SelectCommand>
    Et ce TableAdapter est lui-même utlisé par un GridView, que je tente de remplir dans Page_Load() par un appel à DataBind(). L'appel à DataBind() ne passe aucun paramètre à GetData(), aussi dans Page_Load() ai-je ajouté ces lignes :
    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
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
     
            Parameter par;
     
            /*
            par = new Parameter("@RETURN_VALUE");
            par.Type = TypeCode.Int32;
            par.DefaultValue = null;
            par.Direction = ParameterDirection.ReturnValue;
            this.ObjectDataSource1.SelectParameters.Add(par);
            */
     
            par = new Parameter("@idMin");
            par.Type = TypeCode.Int64;
            par.DefaultValue = null;
            par.Direction = ParameterDirection.Input;
            this.ObjectDataSource1.SelectParameters.Add(par);
     
            par = new Parameter("@idMax");
            par.Type = TypeCode.Int64;
            par.DefaultValue = null;
            par.Direction = ParameterDirection.Input;
            this.ObjectDataSource1.SelectParameters.Add(par);
     
            par = new Parameter("@loadingDateStart");
            par.Type = TypeCode.DateTime;
            par.DefaultValue = null;
            par.Direction = ParameterDirection.Input;
            this.ObjectDataSource1.SelectParameters.Add(par);
     
            par = new Parameter("@loadingDateEnd");
            par.Type = TypeCode.DateTime;
            par.DefaultValue = null;
            par.Direction = ParameterDirection.Input;
            this.ObjectDataSource1.SelectParameters.Add(par);
     
            par = new Parameter("@pageName");
            par.Type = TypeCode.String;
            par.Size = 100;
            par.DefaultValue = null;
            par.Direction = ParameterDirection.Input;
            this.ObjectDataSource1.SelectParameters.Add(par);
     
            par = new Parameter("@language");
            par.Type = TypeCode.String;
            par.Size = 2;
            par.DefaultValue = null;
            par.Direction = ParameterDirection.Input;
            this.ObjectDataSource1.SelectParameters.Add(par);
     
            par = new Parameter("@ip");
            par.Type = TypeCode.String;
            par.Size = 2;
            par.DefaultValue = null;
            par.Direction = ParameterDirection.Input;
            this.ObjectDataSource1.SelectParameters.Add(par);
     
            par = new Parameter("@userAgent");
            par.Type = TypeCode.String;
            par.Size = 255;
            par.DefaultValue = null;
            par.Direction = ParameterDirection.Input;
            this.ObjectDataSource1.SelectParameters.Add(par);
     
            /* ALTERNATIVE :
            this.ObjectDataSource1.SelectParameters.Add("@RETURN_VALUE",     TypeCode.Int32,    null);
            this.ObjectDataSource1.SelectParameters.Add("@idMin",            TypeCode.Int64,    null);
            this.ObjectDataSource1.SelectParameters.Add("@idMax",            TypeCode.Int64,    null);
            this.ObjectDataSource1.SelectParameters.Add("@loadingDateStart", TypeCode.DateTime, null);
            this.ObjectDataSource1.SelectParameters.Add("@loadingDateEnd",   TypeCode.DateTime, null);
            this.ObjectDataSource1.SelectParameters.Add("@pageName",         TypeCode.String,   null);
            this.ObjectDataSource1.SelectParameters.Add("@language",         TypeCode.String,   null);
            this.ObjectDataSource1.SelectParameters.Add("@ip",               TypeCode.String,   null);
            this.ObjectDataSource1.SelectParameters.Add("@userAgent",        TypeCode.String,   null);
            */
     
            this.GridView_List.DataBind();
    J'ai testé
    - avec ou sans le paramètre @RETURN_VALUE,
    - en détaillant chaque paramètre avec sa direction ou simplement avec 3 arguments passés à SelectParameters.Add().
    - avec ou sans les '@'

    Dans tous les cas j'obtiens une exception comme celle-ci :
    ObjectDataSource 'ObjectDataSource1' n'a pas pu trouver une méthode 'GetData' non générique qui a des paramètres : @RETURN_VALUE, @idMin, @idMax, @loadingDateStart, @loadingDateEnd, @pageName, @language, @ip, @userAgent.

    Verriez-vous un truc que j'aurais fait de travers ?
    Pas tout, j'espère...

    Grand merci d'avance
    Fab

  2. #2
    Candidat au Club
    Profil pro
    Inscrit en
    Février 2008
    Messages
    2
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Février 2008
    Messages : 2
    Points : 2
    Points
    2
    Par défaut RESOLU
    OK, j'ai recréé le DataSet, et ça roule. Comme quoi, écrire un petit message, ça aide à réfléchir.

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

Discussions similaires

  1. Problème de binding sur un gridView WPF Toolkit
    Par fragmonster dans le forum Windows Presentation Foundation
    Réponses: 7
    Dernier message: 31/07/2009, 11h39
  2. Problème de DataBind() sur des DropDownList
    Par getz85 dans le forum ASP.NET
    Réponses: 10
    Dernier message: 28/02/2008, 15h31
  3. Réponses: 10
    Dernier message: 18/08/2006, 12h14
  4. [VB.NET] Problème de tri sur Datagrid/gridview multilingue
    Par crimsonPhantom dans le forum ASP.NET
    Réponses: 4
    Dernier message: 16/03/2006, 22h41
  5. [JComboBox] Problème dans le PopMenu après ajout
    Par bidon dans le forum Agents de placement/Fenêtres
    Réponses: 2
    Dernier message: 29/03/2005, 15h52

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