Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. issue with boolean datatype

issue with boolean datatype

Scheduled Pinned Locked Moved ASP.NET
helptutorialquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bigphish
    wrote on last edited by
    #1

    Hi.. I am getting below error while executing this code:last line of code is throwing the error.-"Format exception unhandled by code.String was not recognized as a valid Boolean."

    WinnersBLL objperiods = new WinnersBLL();

            DataTable dt\_GetCurrentPeriod = new DataTable();
             dt\_GetCurrentPeriod = (DataTable)Session\["WinBudget"\];
             GridEditableItem insertedItem = e.Item as GridEditableItem;
            
    
     if(Convert.ToBoolean(dt\_GetCurrentPeriod.Rows\[0\]\["IsCurrentPeriod"\].ToString()) == true)
    

    {
    some task.
    }

    If "Iscurrentperiod" column in the datatable is null ,its giving the error. how to check for null or false ?

    S J 2 Replies Last reply
    0
    • B bigphish

      Hi.. I am getting below error while executing this code:last line of code is throwing the error.-"Format exception unhandled by code.String was not recognized as a valid Boolean."

      WinnersBLL objperiods = new WinnersBLL();

              DataTable dt\_GetCurrentPeriod = new DataTable();
               dt\_GetCurrentPeriod = (DataTable)Session\["WinBudget"\];
               GridEditableItem insertedItem = e.Item as GridEditableItem;
              
      
       if(Convert.ToBoolean(dt\_GetCurrentPeriod.Rows\[0\]\["IsCurrentPeriod"\].ToString()) == true)
      

      {
      some task.
      }

      If "Iscurrentperiod" column in the datatable is null ,its giving the error. how to check for null or false ?

      S Offline
      S Offline
      Sandeep Mewara
      wrote on last edited by
      #2

      bigphish wrote:

      Convert.ToBoolean(dt_GetCurrentPeriod.Rows[0]["IsCurrentPeriod"].ToString())

      Error is raised if the converted string value of dt_GetCurrentPeriod.Rows[0]["IsCurrentPeriod"] is not a 'true' or 'false'. Anything other then them would raise that error. Try something like this:

      if(dt_GetCurrentPeriod.Rows[0]["IsCurrentPeriod"] != null)
      {
      if(Convert.ToBoolean(dt_GetCurrentPeriod.Rows[0]["IsCurrentPeriod"].ToString()) == true)
      {
      //some task.
      }
      }

      B 1 Reply Last reply
      0
      • S Sandeep Mewara

        bigphish wrote:

        Convert.ToBoolean(dt_GetCurrentPeriod.Rows[0]["IsCurrentPeriod"].ToString())

        Error is raised if the converted string value of dt_GetCurrentPeriod.Rows[0]["IsCurrentPeriod"] is not a 'true' or 'false'. Anything other then them would raise that error. Try something like this:

        if(dt_GetCurrentPeriod.Rows[0]["IsCurrentPeriod"] != null)
        {
        if(Convert.ToBoolean(dt_GetCurrentPeriod.Rows[0]["IsCurrentPeriod"].ToString()) == true)
        {
        //some task.
        }
        }

        B Offline
        B Offline
        bigphish
        wrote on last edited by
        #3

        hi.., if,

        dt_GetCurrentPeriod.Rows[0]["IsCurrentPeriod"]

        is 'false' also its giving error..It is working fine only if "IsCurrentPeriod" is true.. If the field is null its taking as false and giving error.I made this as nullable column.

        B 1 Reply Last reply
        0
        • B bigphish

          hi.., if,

          dt_GetCurrentPeriod.Rows[0]["IsCurrentPeriod"]

          is 'false' also its giving error..It is working fine only if "IsCurrentPeriod" is true.. If the field is null its taking as false and giving error.I made this as nullable column.

          B Offline
          B Offline
          bigphish
          wrote on last edited by
          #4

          ANY UPDATE ON THIS? nothing is working for me.. :-(

          1 Reply Last reply
          0
          • B bigphish

            Hi.. I am getting below error while executing this code:last line of code is throwing the error.-"Format exception unhandled by code.String was not recognized as a valid Boolean."

            WinnersBLL objperiods = new WinnersBLL();

                    DataTable dt\_GetCurrentPeriod = new DataTable();
                     dt\_GetCurrentPeriod = (DataTable)Session\["WinBudget"\];
                     GridEditableItem insertedItem = e.Item as GridEditableItem;
                    
            
             if(Convert.ToBoolean(dt\_GetCurrentPeriod.Rows\[0\]\["IsCurrentPeriod"\].ToString()) == true)
            

            {
            some task.
            }

            If "Iscurrentperiod" column in the datatable is null ,its giving the error. how to check for null or false ?

            J Offline
            J Offline
            J 0
            wrote on last edited by
            #5

            bigphish wrote:

            how to check for null or false

            To check for null...

            if (dataRow.IsNull("ColumnName"))...

            To check for false...

            if (!Convert.ToBoolean(dataRow["ColumnName"]))...

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups