Re: Function 'GetData' doesn't return a value on all code paths...

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




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

.



Relevant Pages