Identification of "null" in. NET and SQL Server

Source: Internet
Author: User

For new database programming, we may have some questions about "NULL". For example, if all the data in a new table is displayed as <NULL>, after manually adding and deleting text, it becomes blank again. A string-type field is not explicitly filled in, but not equal to ""; ADO is used. NET value from the database, an error occurs every time there is a <NULL> ...... This requires us to correctly understand several different "null values" in. NET and SQL Server ".
1. The true null value, that is, "No input value", can appear in most types of fields (if there are no other constraints). It is expressed as null in SQL server, displayed as <NULL>. In the SQL server Enterprise Manager, press Ctrl + 0. It corresponds to System. DBNull. Value in. NET. In the T-SQL command, to determine whether a value is null, use "is null" instead of "= null"; to handle a null value, there is an ISNULL function that replaces null with the specified value. Use ADO. the null value obtained from the database cannot be automatically converted to a null string or a Nothing. You must manually check the value if System is obtained. DBNull. value is assigned to the Data Object Nothing or other custom meaningful values.
 
2. A null string (zero-length string) appears only in a string type (such as nvarchar) field. It is expressed as ''in SQL server and displayed as blank, manually enter a cell in the SQL server Enterprise Manager. It corresponds to System. String. Empty in. NET, which is commonly used "". Processing empty strings in T-SQL commands is no different from processing general strings. The Null String obtained from the database using ADO. NET is no different from the general string.
 
Related concepts include VB. the Nothing in NET corresponds to C #. NET null (note that this null is C #. NET, rather than SQL Server), they are in. NET indicates that no empty reference of any object is referenced. When importing SQL server, according to different context, it may be stored as a true null value (for example, when updating a string field value ), it is also possible to call the custom default values in SQL server (for example, to pass a stored procedure parameter with a default value), or it may be caused by the failure of type conversion. NET exception. Therefore, when using ADO. NET to store data to SQL server, use Nothing with caution.

Related Article

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.