我想把下面的C#代码转换成VB.NET
if (dr != null)
dr.Close();
if (con != null && con.State == ConnectionState.Open)
con.Close();
dr = null;在VB.NET中,我找不到任何合适的方法或途径来检查OracleDatareader和OracleConnection对象是否为空。如何在VB.NET中解释上面的代码?我使用System.Data.OrcleClient命名空间来访问Orcale数据库中的数据。
发布于 2020-04-29 01:52:40
在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 = Nothinghttps://stackoverflow.com/questions/61486376
复制相似问题