I am reading a cell from Excel which contains TRUE or FALSE. After reading it I need to insert the value in a table in SQL Server with datatype bit.
I get the value in the cell with this line of code:
   $myvariable =  $WorkbookTotal.Cells.Item($ExcelRowToRead, 10).Text
Is there a way to convert TRUE or FALSE to 1or 0 without  writing an if statement?  I need $myvariable to become a 1/0 value..
You could convert the string value to [bool] with bool.Parse, then convert to [int]:
$myvariable = "TRUE"
$bit = [int][bool]::Parse($myvariable)
After which:
PS ~> $bit
1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With