Problème SqlDataReader ProcédureStockée
Bonsoir, j'ai une erreur "Le cast spécifié n'est pas valide" lorsqu'il arrive à LEC.Add dans le code suivant :
Code:
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
| public static List<ListeEmpruntsClient> VoirEmpruntsClient(int clientId)
{
List<ListeEmpruntsClient> LEC = new List<ListeEmpruntsClient>();
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["TFEBibliConnectionString"].ToString());
SqlCommand comm = con.CreateCommand();
comm.CommandType = CommandType.StoredProcedure;
comm.CommandText = "VoirEmpruntsClient";
SqlParameter param = comm.CreateParameter();
param.ParameterName = "@ClientId";
param.Value = clientId;
param.DbType = DbType.Int32;
comm.Parameters.Add(param);
con.Open();
try
{
SqlDataReader r = comm.ExecuteReader();
while (r.Read())
LEC.Add(new ListeEmpruntsClient(r.GetGuid(0), r.GetDateTime(1), r.GetDateTime(2), r.GetBoolean(3),
r.GetDecimal(4), r.GetInt32(5), r.GetString(6), r.GetInt32(7), r.GetString(8), r.GetInt32(9),
r.GetString(10)));
return LEC;
}
catch
{
throw new Exception("Erreur de lecture des emprunts du client.");
}
finally
{
con.Close();
}
} |
D'habitude j'arrive à trouver l'erreur, mais là je coince.
Voici la procédure stockée :
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| ALTER PROCEDURE dbo.VoirEmpruntsClient
(
@ClientId INT
)
AS
SELECT EMPRUNT.Id, EMPRUNT.DateEmprunt, EMPRUNT.DateRetour, EMPRUNT.EstRendu, EMPRUNT.Amende, EMPRUNT.ClientId,
CLIENT.Nom, EMPRUNT.EmployeId, EMPLOYE.Nom, EMPRUNT.LivreId, LIVRE.Titre FROM EMPRUNT
INNER JOIN EMPLOYE ON EMPRUNT.EmployeId = EMPLOYE.Id
INNER JOIN CLIENT ON EMPRUNT.ClientId = CLIENT.Id
INNER JOIN LIVRE ON EMPRUNT.LivreId = LIVRE.Id
WHERE EMPRUNT.ClientId = @ClientId
RETURN |
Et voici la table :
Code:
1 2 3 4 5 6 7 8
| Id char(36)
DateEmprunt datetime
DateRetour datetime
EstRendu bit
Amende money
EmployeId int
ClientId int
LivreId int |
Aucune donnée n'est null.
Merci d'avance.