private SqlBoolean ToBoolean(string s) { SqlBoolean value; if (SqlBoolean.TryParse(s, out value)) { return(value); } if (String.Equals(s, "1")) { return(SqlBoolean.True); } if (String.Equals(s, "2")) { return(SqlBoolean.False); } throw new InvalidCastException(String.Format("Could not convert string '{0}' of type '{1}' to BOOLEAN", s, TypeCode.ToString().ToUpperInvariant())); }