c# - Cannot implicitly convert type 'string' to 'bool' CheckBox -


i'm trying convert vb.net c# read data sql database. following code gives me error."cannot implicitly convert type 'string' 'bool'". works fine in vb. how can convert statement c#?

chknewemployee.checked = dr["chknewemployee"].tostring(); 

chknewemployee.checked = convert.toboolean(dr["chknewemployee"]); 

toboolean:

true or false, reflects value returned invoking iconvertible.toboolean method underlying type of value. if value null, method returns false.

depending on needs may want try bool.parse or bool.tryparse

update

bool.parse, bool.tryparse , convert.toboolean:

  • are case insensitive
  • ignore leading , trailing white space

bool.parse:

  • correct value either true or false
  • throws formatexception in case of failed conversion

bool.tryparse:

  • correct value either true or false
  • doesn't throw exception in case of failed conversion
  • return true if conversion succeeded, otherwise false
  • conversion result saved via second parameter (out bool result)

convert.toboolean:

  • correct value true, false or null (returning false in case of null)
  • throws formatexception in case of failed conversion

Comments