Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

vb.net

In VB.Net you can write :

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

What is the equivalent of method IsDBNull in C#?

like image 444
Chandrasekhar Sahoo Avatar asked Mar 31 '15 12:03

Chandrasekhar Sahoo


People also ask

What is C used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is C language in simple words?

C is a structured, procedural programming language that has been widely used both for operating systems and applications and that has had a wide following in the academic community. Many versions of UNIX-based operating systems are written in C.

What is the C in history?

C was originally developed for UNIX operating system to beat the issues of previous languages such as B, BCPL, etc. The UNIX operating system development started in the year 1969, and its code was rewritten in C in the year 1972.


2 Answers

if (!DBNull.Value.Equals(oCustomerNameDataRow[0]))
{
  //something
}

MSDN (DBNull.Value)

like image 104
Дмитрий Чистик Avatar answered Oct 11 '22 22:10

Дмитрий Чистик


I would say the the equivalent of the IsDBNull method (Microsoft.VisualBasic.Information) located in the Microsoft.VisualBasic assembley

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)

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

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);
like image 9
Bjørn-Roger Kringsjå Avatar answered Oct 12 '22 00:10

Bjørn-Roger Kringsjå