7

次のエラーが表示されます。

関数 'getkey' は、すべてのコード パスで値を返すわけではありません。結果が使用されると、実行時に null 参照例外が発生する可能性があります。

次のコードに:

 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

考えられるすべての解決策を試しましたが、うまくいきませんでした。どんな助けでも大歓迎です。

4

2 に答える 2