Aalhussein

Aalhussein

  • 1.6k
  • 133
  • 10k

how to capture bit database column field into a checkbox property

Dec 17 2020 8:15 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 (1)