. "Null value" discrimination in net and SQL Server
Source: Internet
Author: User
Beginner database Programming We may have some questions about "null value", for example, all the data in a newly created table is displayed as <null>, and the text is blank when you manually add and delete it, and a field of string type is not equal to "" ; Use Ado.net to take value from the database, every encounter with <NULL> error ... This requires our correct understanding. NET, and several different "null values" in SQL Server.
1, the real null value, that is, "no input value", can appear in most types of fields (if there are no other constraints), SQL Server is represented as NULL, shown as <null>, and the method that is entered manually in SQL Server Enterprise Manager is to press CTRL +0. It's in. NET in the corresponding System.DBNull.Value. In the T-SQL command, determine if a value is null, use "is null" instead of "= null"; There is a isnull function to handle null values, which replaces null with the specified value. Null values obtained from the database by Ado.net cannot be automatically converted to an empty string or nothing, and must be detected manually: If you get System.DBNull.Value, you assign nothing to the data object or any other custom meaningful value.
2, the empty string (0-length string), only appears in the field of string type (such as nvarchar), is represented as "in SQL Server", is displayed as blank, and empties a cell when entered manually in SQL Server Enterprise Manager. It's in. NET in the corresponding System.String.Empty, which is our common "". There is no difference between handling an empty string in a T-SQL command and handling a generic string. The empty string obtained from the database with Ado.net is no different from the normal string.
The related concepts also include nothing in vb.net and corresponding to C #. NET (note that this null is C #.) NET rather than NULL in SQL Server. NET is a value that represents a null reference that does not refer to any object, and may be stored as a real null value (for example, when updating a field value of a string type) in SQL Server, depending on the context environment, or in SQL A custom default value in the server, such as passing a stored procedure parameter with a default value, may also be thrown because the type conversion cannot be performed. NET exception. So use nothing when you store data in SQL Server with Ado.net.
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.