A boolean variable with a null value

Source: Internet
Author: User
C # Language Reference Bool (C # reference)

The bool keyword is the alias of system...:. boolean. It is used to declare variables to store Boolean values true and false.

If you need a Boolean variable with a null value, use bool ?. For more information, see the empty type (C # programming guide ).

The following code is used to understand how to read data from the database. 1. Read the public static object setvalue (bool? Inputvalue) {OBJ outvalue = dbnull. value; // because in the dB, the null value has one specifical. If (inputvalue! = NULL) {outvalue = (object) inputvalue;} return outvalue;} 2. Read from the database.

Public static bool? Getboolandnullfield (Object inputvalue)
{

Bool? Outvalue = false;

If (inputvalue = NULL)

{

Outvalue = (bool ?) NULL;

}

Else if (inputvalue = dB. value)

{

Outvalue = (bool ?) NULL;

}

Else

Outvalue = (bool ?) Inputvalue;

Return outvalue;
}

The above two functions are encapsulated.

The following is an example:

We just read the database, such as parm. Add (New dbparameter ("@ paraname1", dbtype. Boolean, setvalue (input )));

In this way, we will convert it to the corresponding Boolean to read into the database. As for null, it is because the database has a special null value. if it is null, the database reads null.

 

The same is true for database reading.

Getboolandnullfield (R ["columnname1"]);

In this example, we can encapsulate such types as string, Int, datetime, short, and decimal to read null correctly in the database.

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.