473,569 Members | 2,480 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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
ConnectionStrin g As String, ByVal strQuery As String) As DataTable
Try

GetData = New DataTable

If ConnectionType = "SQL" Then

Dim da As SqlDataAdapter

da = New SqlDataAdapter( strQuery, ConnectionStrin g)

da.Fill(GetData )

Else

Dim da As OdbcDataAdapter

da = New OdbcDataAdapter (strQuery, ConnectionStrin g)

da.Fill(GetData )

End If

Catch ex As Exception

MsgBox(ex.Messa ge)

End Try

End Function
--
Filip
http://users.skynet.be/101airborne
Official Site of the 101st Airborne - 463rd PFA
skype: airborne463pfa-fiwi
-------------------------------------------------
Jul 13 '06 #1
6 4106
You have missed the return so that's why you have that warning. If you
have a function, always set a return something.

Hope this help,

Regards,

----

C.Marcelino

Jul 13 '06 #2

"VoTiger" <ch************ ******@gmail.co mschreef in bericht
news:11******** **************@ h48g2000cwc.goo glegroups.com.. .
You have missed the return so that's why you have that warning. If you
have a function, always set a return something.

Hope this help,

Regards,

----

C.Marcelino
Yes, I tried to do that at the end "Return Getdata" but then I had this :
Variable 'GetData' is used before it has been assigned a value. A null
reference exception could result at runtime.
--
Filip
http://users.skynet.be/101airborne
Official Site of the 101st Airborne - 463rd PFA
skype: airborne463pfa-fiwi
-------------------------------------------------
Jul 13 '06 #3
It's seems to be normal because you are making :
GetData = new datatable
But you are not using it... try to put a value in it and then return
it. Or if it's normal that you don't set it with values, just put it to
NULL.

I am waiting for more.

Regards,

----

C.Marcelino

Jul 13 '06 #4

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
ConnectionStrin g As String, ByVal strQuery As String) As DataTable
Try

GetData = New DataTable

If ConnectionType = "SQL" Then

Dim da As SqlDataAdapter

da = New SqlDataAdapter( strQuery, ConnectionStrin g)

da.Fill(GetData )

Else

Dim da As OdbcDataAdapter

da = New OdbcDataAdapter (strQuery, ConnectionStrin g)

da.Fill(GetData )

End If

Catch ex As Exception

MsgBox(ex.Messa ge)

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

Jul 13 '06 #5

"VoTiger" <ch************ ******@gmail.co mschreef in bericht
news:11******** **************@ h48g2000cwc.goo glegroups.com.. .
It's seems to be normal because you are making :
GetData = new datatable
But you are not using it... try to put a value in it and then return
it. Or if it's normal that you don't set it with values, just put it to
NULL.

I am waiting for more.

Regards,

----

C.Marcelino
in the catch section I had already a messagebox, and I added Getdata =
Nothing.
I got no warnings anymore.
Thanks !
Jul 13 '06 #6
No problem you are welcome. Just think like this : a SUB returns
nothing so no need to put "return" but a FUNCTION always return a thing
so ... use "return blablabla".

Regards,

----

C.Marcelino

Jul 13 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
4940
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my webserver runs that part of the script (see attached file, snippet.php), though, it doesn't go through. I don't get an error message or...
4
2146
by: a | last post by:
I have been cleaning up somebody else's code in Vs2005 .net 2.0 There wer lots of these code pat errors because of unitialized variables in functions with Conditionals - that may or may not be set . These I have cleaned up ok. But I have a few like this one below. The error is Function BindData doesn't return a value on all code...
27
3103
by: Terry | last post by:
I am getting the following warning for the below function. I understand what it means but how do I handle a null reference? Then how do I pass the resulting value? Regards Warning 1 Function 'Dec2hms' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.
0
7701
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7615
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7677
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7979
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3643
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.