Aalhussein

Aalhussein

  • NA
  • 133
  • 10.2k

how to pull bool datatype field in db into a checkbox property

Dec 17 2020 5:47 AM
I am pulling data from database to a datareader object "dr"
once I iterate throught the dr, I need to pull its value to a variable :
bool profileComplete = dr["profileComplete"] // this caused error stating that cannot implicitely convert type 'object' to a bool .
My question, why when I use bool.Parse, in code below, shows a message " cannot convert from object to a string "
profileComplete = bool.Parse(dr["profileComplete"]
However, when I add .ToString() it works:
profileComplete = bool.Parse(dr["profileComplete"].ToString());
By the way, the datatype of profileComplete in the database is bit ( 0,1 )
// this is what I need to do , to populate a checkbox with a value from db
cbProbileComplete.Checked = profileComplete ;

Answers (2)