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...
... et qui fonctionne :
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
me sort bien la totalité des rows contenus dans la table.
Code : Sélectionner tout - Visualiser dans une fenêtre à part execute dbo.sp_SelectHist null,null,null,null,null,null,null,null;
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 :
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 <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>
J'ai testé
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();
- 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
Partager