我收到此错误:
函数“getkey”不会在所有代码路径上返回值。
当结果为空引用异常时,可能会在运行时发生
用过的。
到以下代码:
Public Function getkey(ByVal id As String)
Dim cmd As SqlCommand
Try
cmd = New SqlCommand("dbo.getkeydesc", GenLog.cn)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@id", id)
Dim r As SqlDataReader = cmd.ExecuteReader()
If r.HasRows Then
Return True
Else
Return False
End If
Catch ex As Exception
MsgBox(ex.ToString)
Finally
' If Not cn Is Nothing Then cn.Close()
End Try
End Function
我尝试了所有可能的解决方案,但它们不起作用。
任何帮助,将不胜感激。
The Catch
块不返回值。将其更改为返回值的位置,如下所示:
Public Function getkey(ByVal id As String)
Dim cmd As SqlCommand
Try
cmd = New SqlCommand("dbo.getkeydesc", GenLog.cn)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@id", id)
Dim r As SqlDataReader = cmd.ExecuteReader()
If r.HasRows Then
Return True
Else
Return False
End If
Catch ex As Exception
MsgBox(ex.ToString)
Return False
Finally
' If Not cn Is Nothing Then cn.Close()
End Try
End Function
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)