Bien le bonsoir à tous.

J'ai un petit soucis qui dois être bête mais je n'arrive pas

J'ai tout d'abord trois tables et voici leur create :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
 
CREATE  TABLE Commande (
  Id_Commande uniqueidentifier ROWGUIDCOL  NOT NULL CONSTRAINT [DF_Commande]  DEFAULT (newid()),
  Etat_Commande bit NOT NULL ,
  Clorture BIT NOT NULL ,
  Table_Id uniqueidentifier NOT NULL ,
  PRIMARY KEY (Id_Commande) ,
  CONSTRAINT fk_Commande_Table1
    FOREIGN KEY (Table_Id )
    REFERENCES Tables (Id_Tables )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
GO
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
 
 
------------------------------------Article-------------------------------------------------------------------------
Create TABLE Article (
  Id_Article uniqueidentifier ROWGUIDCOL  NOT NULL CONSTRAINT [DF_Articles] DEFAULT (newid()),
  IdFamille uniqueidentifier NOT NULL ,
  Nom_Article VARCHAR(45) NULL ,
  CodeBarre_Article VARCHAR(13)NOT NULL ,
  Designation VARCHAR(145) NULL ,
  Visible BIT NOT NULL , 
  Qte_Stock smallint NOT NULL ,  
  Seuil_Articles_Min smallint NOT NULL ,
  Prix_Achat decimal(18, 0) NOT NULL,
  Prix_Vente_Article decimal(18, 0) NOT NULL,
  Marge decimal(18, 0) NOT NULL,
  Constraint pk_article PRIMARY KEY (Id_Article),
  CONSTRAINT fk_Article_Famille FOREIGN KEY (IdFamille)REFERENCES dbo.Famille (IdFamille)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
GO
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
---------------------------------Articles_Commandes---------------------------------------------------------------
CREATE  TABLE Articles_Commandes (
  Id_Articles_Commandes uniqueidentifier ROWGUIDCOL  NOT NULL CONSTRAINT [DF_Articles_Commandes]  DEFAULT (newid()),
  Id_Commandes uniqueidentifier  NOT NULL,
  Article_Id uniqueidentifier NOT NULL ,
  Quantite smallint NULL ,
  Payer BIT NULL ,
  constraint pk_articles_commandes PRIMARY KEY (Id_Articles_Commandes) ,
  CONSTRAINT fk_Commande_has_Article_Commande
    FOREIGN KEY (Id_Commandes )
    REFERENCES Commande (Id_Commande )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT fk_Commande_has_Article_Article1
    FOREIGN KEY (Article_Id )
    REFERENCES Article (Id_Article )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
GO
Ca donne une commande ->article_commande -> Article.

J'ai ensuite une procédure stockée qui me permet de faire la sum des articles par commande par date. Donc par exemple nous sommes le 15/09/2010, et bien je veux la somme de tous les articles passer aujourd'hui:

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
 
USE [Cafer]
GO
/****** Object:  StoredProcedure [dbo].[usp_get_close]    Script Date: 09/15/2010 16:24:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[usp_get_close]
@Date datetime,
@Gains decimal OUTPUT
AS
BEGIN
SELECT @Gains = Sum(Prix_Vente_Article)
FROM   [Article] Tab_art                      
       JOIN [Articles_Commandes] Tab_Art_com              
            ON Tab_art.[Id_Article] = Tab_Art_com.[Article_Id]
       JOIN [Commande] Tab_com                  
            ON Tab_Art_com.[Id_Commandes] = Tab_com.[Id_Commande]
where Tab_com.Date >= CONVERT(DateTime,@date,120) and Tab_com.Date <= CONVERT(DateTime,@date+1,120)
 
End
Quand je la test ca fonctionne très bien, ca me renvoi une bonne valeur.

Le soucis arrive au niveau de mon code csharp:

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
 
myCmd.Parameters.Clear();
                        myCmd.CommandType = CommandType.StoredProcedure;
                        SqlParameter param;
 
                        param = new SqlParameter("@Date", SqlDbType.DateTime);
                        param.Direction = ParameterDirection.Input;
                        param.Value = dateTime;
                        myCmd.Parameters.Add(param);
 
                        param = new SqlParameter("@Gains", SqlDbType.Decimal);
                        param.Direction = ParameterDirection.Output;
                        myCmd.Parameters.Add(param);
 
                        myCmd.ExecuteNonQuery();
 
                        myConn.Close();
                        Decimal toto = (Decimal)myCmd.Parameters["@Gains"].Value;
Il me renvoie une erreur au niveau du cast alors que tout est correcte au niveau des differentes valeur(procedure ...)

Quelqu'un aurait-il une petite idée pour me secourir ?

Merci bien et une bonne fin de journée

IoIO