Invalid cast exception when reading result from SQLDataReader

前端 未结 4 875
轻奢々
轻奢々 2021-02-19 05:31

My stored procedure:

    @UserName nvarchar(64),

    AS

    BEGIN
    SELECT MPU.UserName, SUM(TS.Monday)as Monday //TS.Monday contains float value
    FROM db         


        
4条回答
  •  执念已碎
    2021-02-19 05:50

    I also had a similar issue and ended up doing this:

    if (!oDR.IsDBNull(0))
        Rating = (float)oDR.GetSqlDecimal(0).Value;
    

    oDR.GetFloat(0) was returning and invalid cast exception when accessing the result of a SELECT AVG(...).

    HTH

提交回复
热议问题