Net convert null to string

System Requirements: Windows 8, Windows 7, Windows 8.1


foreach ( Property Info Property Item in this. Get Type. Get Properties Property Item. Set Value(this, obj Data Table. Rows[0][ Property Item. Name. To String ], null In one of the loops i get this exceptional error: Object of type ' System. DBNull' cannot be converted to type ' System. String'. The error occurs because one of the fields in the database has no value (null so the string property could not handle it. How can i convert this null to string? I got this solution If you know a shorter or better one, feel free to post it. I'm trying to avoid checking on every loop is current value is null or not.
 Returns an indication whether the specified object is of type DBNull. Namespace:   System Assembly:  mscorlib (in mscorlib.dll) The Is DBNull method tests whether the value parameter is equal to DBNull. Value. It is equivalent to the following code: return DBNull. Value. Equals(value Note DBNull. Value is used to indicate a value that is missing. It is not equivalent to null or to String. Empty. Therefore, code such as Convert. Is DBNull(null) in C or Convert. Is DBNull( Nothing) in Visual Basic returnsfalse. The following example uses a Sql Data Reader object to retrieve survey data from a database. It assigns each row's field values to an array, and then passes each array element to the Is DBNull method. If the method returns true, the example assigns the string NA to the array element. The array is then added to the Rows collection of a System. Windows. Forms. Data Grid View control. private void Form1_ Load(object sender, Event Args e) / Define ADO. NET objects. Sql Connection conn = new Sql Connection(connection String Sql Command cmd = new Sql Command Sql Data Reader dr; / Open connection, and retrieve dataset. conn. Open / Define Command object. cmd. Command Text = Select * From Responses ; cmd. Command Type = Command Type. Text; cmd. Connection = conn; / Retrieve data reader. dr = cmd. Execute Reader int field Count = dr. Field Count; object[] field Values = new object[field Count]; string[] headers = new string[field Count]; / Get names of fields. for (int ctr = 0; ctr < field Count; ctr+) headers[ctr] = dr. Get Name(ctr / Set up data grid. this.grid. Column Count = field Count; this.grid. Column Headers Default Cell Style. Back Color = Color. Navy; this.grid. Column Headers Default Cell Style. Fore Color = Color. White; this.grid. Column Headers Default Cell Style. Font = new Font(this.grid. Font, Font Style. Bold this.grid. Auto Size Rows Mode = Data Grid View Auto Size Rows Mode. Displayed Cells Except Headers;.
 Indicates whether the specified string is null or an Empty string. Namespace:   System Assembly:  mscorlib (in mscorlib.dll) Is Null Or Empty is a convenience method that enables you to simultaneously test whether a String is null or its value is Empty. It is equivalent to the following code: result = s = null | s = String. Empty; You can use the Is Null Or White Space method to test whether a string is null, its value is String. Empty, or it consists only of white-space characters. A string is null if it has not been assigned a value (in C+ and Visual Basic) or if has explicitly been assigned a value of null. Although the composite formatting feature can gracefully handle a null string, as the following example shows, attempting to call one if its members throws a Null Reference Exception. using System; public class Example public static void Main String s = null; Console. Write Line( The value of the string is ' 0 ', s try Console. Write Line( String length is 0, s. Length catch ( Null Reference Exception e) Console. Write Line(e. Message / The example displays the following output: / The value of the string is ' / Object reference not set to an instance of an object. A string is empty if it is explicitly assigned an empty string ( ) or String. Empty. An empty string has a Length of 0. The following example creates an empty string and displays its value and its length. String s = ; Console. Write Line( The length of ' 0 ' is 1., s, s. Length / The example displays the following output: / The length of ' is 0. The following example examines three strings and determines whether each string has a value, is an empty string, or is null. using System; class Sample public static void Main string s1 = abcd ; string s2 = ; string s3 = null; Console. Write Line( String s1 0., Test(s1 Console. Write Line( String s2 0., Test(s2 Console. Write Line( String s3 0.