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"]); 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
- correct value either
trueorfalse - throws
formatexceptionin case of failed conversion
- correct value either
trueorfalse - doesn't throw exception in case of failed conversion
- return
trueif conversion succeeded, otherwisefalse - conversion result saved via second parameter (
out bool result)
- correct value
true,falseornull(returningfalsein case ofnull) - throws
formatexceptionin case of failed conversion
Comments
Post a Comment