Differences between IsDBNull and IsNullOrEmpty

Source: Internet
Author: User
Sometimes, when a certain bit of information is Null, ASP. NET cannot present such Null values on the current plane. Because ASP. NET does not automatically convert the Null value into a String, there will be a warning message ....... For the definition of Null, refer to the related documents.

For example, the value of test123 in a dataset is "Null 」.
So, we want to present this location on the website, and the following itinerary will definitely go wrong! <% Response. Write (Dr. Item ("test123 ")) %>

To avoid this exception, in the Code Behind field, we must have an IF clause to prevent blocking:

IFNotDr. Item ("test123 ")Is DBNull. ValueThen
'-- Unknown solution: if the value of test123 digit is not "Null", it will continue this region.
Response. Write (dr. Item ("test123 "))
End IF

If you are using the data transfer calculation formula (. aspx partition) in HTML, use the following method:
Convert. IsDBNull (Eval ("column "))

Or

Eval ("Column"). Equals (System. Data. DbNull)
Data source:Http://tw.knowledge.yahoo.com/question/question? Qid = 1508091105980

Abstract:The NULL value of the item is a tagIt indicates that the information is currently empty, and its nature is different from that of the Null string. Therefore, string is used. isNullOrEmpty (myField. value) is unable to determine whether it is a NULL Value, which means that DataRow must provide an IsNull () method, and DataReader must have one IsDBNull () is because of the forward feature of the NULL value.
[Qiu Feng: The above materials are from Microsoft Senior MVP]
Bytes ------------------------------------------------------------------------------------
Differences between NULL, "", DBNULL, String. Empty, Convert. IsDBNull () in C #

Best Answer
Null is the C # keyword, indicating that no empty reference of any object is referenced. Null is the default value of the reference type variable. DBNULL indicates a class, indicating a null value. This class indicates that no known value exists (usually in database applications ). In database applications, empty objects are valid values of fields. This class distinguishes between null values (empty objects) and uninitialized values (DBNull. Value instances ). For example, a table can contain records with uninitialized fields. By default, these uninitialized fields have DBNull values. String. empty indicates an Empty string. This attribute is read-only. convert. isDBNULL (object value) is a method used to determine whether the parameter object is of the DBNULL object type. If it is true, it is not false.
Null can be assigned to any variable. Setting the variable to null DBNull is only used for the DataRow object, indicating that String. Empty is a 0-length String Convert. IsDBNull in the database to determine whether it is DBNull.

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.