locked
Specified cast is not valid RRS feed

  • Question

  • User-1499457942 posted

    Hi

      I have below code . It is giving above error . Closed is an Option Type & 0,1 is stored in Database

    int status = (int)rdr["Closed"];

    Thanks

    Thursday, July 19, 2018 6:49 AM

All replies

  • User1992938117 posted

    Try

    int status = (int)rdr["Closed"].ToString();

    Thursday, July 19, 2018 7:03 AM
  • User-1499457942 posted

    Hi

      It is giving error - Cannot convert type to string

    int status = (int)rdr["Closed"].ToString();

    Thanks

    Thursday, July 19, 2018 12:22 PM
  • User-369506445 posted

    Hi

    It seems your value is thanks, please check this

    int status = string.IsNullOrEmpty(rdr["Closed"]) ? 0:(int)rdr["Closed"].ToString();

    Thursday, July 19, 2018 1:26 PM
  • User-82109136 posted
    int status = int.Parse(rdr["Closed"].ToString());

    or

    int status;
    if (int.TryParse(rdr["Closed"].ToString(),out status))
    {
         //Your code here
    }

    Thursday, July 19, 2018 2:12 PM