Free Code Snippets in C#, Net Framework, Office 365, ASP.Net,WPF, Visual Studio, SQL Server, Antivirus free



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




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


<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 #: 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
How may you replace the word: this in a global static method?


Contact for Jobs, Project Requests: