Re: Function 'GetData' doesn't return a value on all code paths...
- From: "Larry Lard" <larrylard@xxxxxxxxxxx>
- Date: 13 Jul 2006 02:57:12 -0700
Screaming Eagles 101 wrote:
Hi, I got this warning, but I don't have a clue on how to resolve it the
best way,
maybe one of you can help.
Application is running smoothly, it's only a warning, but I'd like to
resolve it.
This is the Warning
Function 'GetData' doesn't return a value on all code paths. A null
reference exception could occur at run time when the result is used.
and this is the code:
Public Function GetData(ByVal ConnectionType As String, ByVal
ConnectionString As String, ByVal strQuery As String) As DataTable
Try
GetData = New DataTable
If ConnectionType = "SQL" Then
Dim da As SqlDataAdapter
da = New SqlDataAdapter(strQuery, ConnectionString)
da.Fill(GetData)
Else
Dim da As OdbcDataAdapter
da = New OdbcDataAdapter(strQuery, ConnectionString)
da.Fill(GetData)
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Function
What will be returned if the DataTable constructor throws an exception?
Put a Return statement in the Catch block.
--
Larry Lard
Replies to group please
When starting a new topic, please mention which version of VB/C# you
are using
.
- References:
- Function 'GetData' doesn't return a value on all code paths...
- From: Screaming Eagles 101
- Function 'GetData' doesn't return a value on all code paths...
- Prev by Date: Re: converting short to unicode without System.Text.UnicodeEncoding
- Next by Date: Re: checking MP3 license
- Previous by thread: Re: Function 'GetData' doesn't return a value on all code paths...
- Next by thread: Form1_KeyUp
- Index(es):
Relevant Pages
|