How to Convert a Null Nullable Bool to a Bool


In my application, a bit field with the values NULL, 0, or 1 is executed in the SQL Server database.

Under the connection in Asp.Net Core MVC C # is the table field as Bool? Nullable defined.

With each further processing but then it comes to problems, because bool and bool? Not easy to be assigned.


Asp.Net C #: Bool zero to bool


How to Convert a Nullable Bool Variable to a Bool

With Contert.ToBoolean works without problems. If NULL is passed, then false

item.has_Profil_Image = Convert.ToBoolean(row.has_Profil_Image);




Transfer from data model nullable to a view output

//< Data >

Notes_Index_DataModel item = new Notes_Index_DataModel();

item.Note = row.n;

item.Username = row.UserName;

item.has_Profil_Image = Convert.ToBoolean(row.has_Profil_Image);

//</ Data >


//< add >


//</ add >


Passing Bool? To bool

Asp.Net C #: Bool zero to bool


<td style="padding:0;text-align:left;font-size: 12px; color: #757575;">

    @{ if (item.has_Profil_Image)


            <img src="~/User_Files/User_Images/80/User_Image_1.jpg" style="border-radius:50%"/>






Image is displayed if profile image exists. If NULL or 0 or -1 nothing is displayed

Asp.Net C #: Bool zero to bool

Software Entwicklung Stuttgart NĂ¼rtingen
Suche Projekte C#, WPF, Windows App,ASP.Net, vb.Net, WinForms, SQL Server, Access, Excel