What is the C# equivalent of VB.Net " IsDBNull"
11,138
Solution 1
if (!DBNull.Value.Equals(oCustomerNameDataRow[0]))
{
//something
}
Solution 2
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);
Related videos on Youtube
Author by
Chandrasekhar Sahoo
Updated on June 04, 2022Comments
-
Chandrasekhar Sahoo almost 2 years
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#?
-
majjam about 9 years
-
Random Dev about 9 yearsto the downvoters: this is a viable and good question - either find a reason to flag it (for example it might have been asked before) or stop downvoting things - thank you
-
Rick Davin about 9 yearsI did not downvote but it this seems to be something that could have easily been looked up on MSDN.
-
-
Random Dev about 9 yearsyep - from System.DBNull
-
Kiquenet about 4 yearsNOT SAME FOR VB.NET NET 4.5 IsDBNull:
If (Expression IsNot Nothing) Then flag = If(Not TypeOf Expression Is DBNull, False, True) Else flag = False End If