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.