What is the C # equivalent for VB.Net "IsDBNull"

In VB.Net you can write:

If Not IsDBNull(oCustomerNameDataRow(0)) Then cbCustomerName.Items.Add(oCustomerNameDataRow(0).ToString End If 

What is equivalent to IsDBNull method in C #?

+10
source share
3 answers
 if (!DBNull.Value.Equals(oCustomerNameDataRow[0])) { //something } 

MSDN (DBNull.Value)

+11
source

I would say that this is the equivalent of the IsDBNull method (Microsoft.VisualBasic.Information) located in the Microsoft.VisualBasic assembly.

 Public Function IsDBNull(ByVal Expression As Object) As Boolean If Expression Is Nothing Then Return False ElseIf TypeOf Expression Is System.DBNull Then Return True Else Return False End If End Function 
 Dim result As Boolean = IsDBNull(Nothing) 

this is the IsDBNull method (System.Convert) located in the mscorlib assembly :

 public static bool IsDBNull(object value) { if (value == System.DBNull.Value) return true; IConvertible convertible = value as IConvertible; return convertible != null? convertible.GetTypeCode() == TypeCode.DBNull: false; } 
 bool result = System.Convert.IsDBNull(null); 
+6
source

try it:

create Extension Method . follow this:

 public static bool IsDBNull(this object val) { return Convert.IsDBNull(val); } 

and the benefits of this Extension Method .

 if(oCustomerNameDataRow[0].IsDBNull()) { // ... } 

I hope that is helpful.

0
source

Source: https://habr.com/ru/post/1216535/


All Articles