简体   繁体   中英

Trying to convert VB.NET code to C#. IsDBNull issue

I dont know how much code you would need but if you would like more id be happy to oblige

here is my attempt so far:

if(AliasNum == null || IsDBNull(AliasNum)
    return

Here is the VB code that Im trying to convert

If AliasNum = Nothing Or IsDBNull(AliasNum) Then
    Exit Sub
End If

You can use the DBNull.Value.Equals Method to determine if the value is equal to DBNull .

if(AliasNum == null || DBNull.Value.Equals(AliasNum)
   return

Based on your comment, AliasNum is of type string . Maybe you want:

if (AliasNum == null || AliasNum.Length == 0)
    return;

The "IsDBNull" function you are calling in the original VB code is from the Microsoft.VisualBasic.Information module. The closest .NET equivalent is the System.Convert.IsDBNull method:

if (AliasNum == null || System.Convert.IsDBNull(AliasNum))
{
    return;
}

Also, the original "AliasNum = Nothing" syntax suggests that "AliasNum" is an instance of a value type, so you may need to change "AliasNum == null" to "AliasNum == default value of the type of AliasNum".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM