,c# operation database DataTable about NULL NULL judgment

Source: Internet
Author: User
Tags null null

Double d=0;
if (! Convert.isdbnull (Datatable.rows[i][m]))
String Str=datatable.rows[i][m]. ToString (). Trim ();
if (! String.IsNullOrEmpty (str))//non-empty string
if (Double.tryparse (str,out D))//d is the correct number
D at this point can be assigned to the other

DBNull:D Bnull is a class, DBNull.Value is its only instance, which refers to the value of NULL (<NULL>) data in the database
null: Represents a null reference that does not reference any object, and does not exist for this field
Convert.isdbnull () can tell if an object is DBNull.Value
Example :
A database table structure is
ID Name Score
1 Hello <null>
Populating the above table data into a DataTable instance of a DataTable in. Net
Remove score Value
datatable.rows[0]["Score"] is the DBNull.Value instance.,c# operation database DataTable about NULL NULL judgment

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: 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.