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
true
orfalse
- throws
formatexception
in case of failed conversion
- correct value either
true
orfalse
- doesn't throw exception in case of failed conversion
- return
true
if conversion succeeded, otherwisefalse
- conversion result saved via second parameter (
out bool result
)
- correct value
true
,false
ornull
(returningfalse
in case ofnull
) - throws
formatexception
in case of failed conversion
Comments
Post a Comment