正在VB.NET中检查Datareader和Connection对象为NULL



我想将以下C#代码转换为VB.NET

if (dr != null)
dr.Close();
if (con != null && con.State == ConnectionState.Open)
con.Close();
dr = null;

在VB.NET中,我找不到任何合适的方法来检查OracleDatareader和OracleConnection对象是否为NULL。如何在VB.NET中解释上述代码?我正在使用System.Data.OrcleClient命名空间访问Orcale数据库中的数据。

在vb.net中,!=null变成IsNot Nothing&&变成andAlso。我们需要使用AndAlso来获得第二个if语句中的短路。最后,==就是=

因此,最终结果是:

If dr IsNot Nothing Then
dr.Close()
ElseIf con IsNot Nothing AndAlso con.State = ConnectionState.Open then
con.Close()
End If
dr = Nothing

最新更新