Freelance Project Requests info@CodeDocu.de Software Development in C# WPF Asp.Net Core Vba Excel Word SQL-Server EF Linq, UWP Net
#

 

 

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.

 

 

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);

 

 

Example:

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 >

dataList.Add(item);

//</ add >

 

Passing Bool? 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%"/>

        }

    }

    @item.Username

</td>

 

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

Mobile
»
C #: Converting a 2D Object Array to 2D String Array
»
Asp.Net C #: Optional parameters in method
»
Asp.Net C #: Bool zero to bool
»
C#: Add Item to Array or List
»
C#: Split String into single Words String-Array
»
C#: Convert TimeSpan in Units of time, Seconds, Minutes
»
C#: convert var to int.
»
C#: Convert Var to Int
»
C#: line break in the code line new line
»
C#: Short Code in one line: result from if - else- then

.

Contact for Jobs, Project Requests: raimund.popp@microsoft-programmierer.de