Question : Variable 'dataRS' is used before it has been assigned a value.  A null reference exception could result at runtime.

Can you assist me in eliminating this warning?  I am getting a runtime error for certain groups when I am logged into the published application with certain permissions.  When I am in visual studio 2005, I have no errors, I only have one warning: "Variable 'dataRS' is used before it has been assigned a value.  A null reference exception could result at runtime.  This is the message I am getting from the published application:
Server Error in '/Assessment' Application.

--------------------------------------------------------------------------------

Runtime Error
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.

Details: To enable the details of this specific error message to be viewable on remote machines, please create a tag within a "web.config" configuration file located in the root directory of the current web application. This tag should then have its "mode" attribute set to "Off".

 

 

   
       
   


 


Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's configuration tag to point to a custom error page URL.

 

 

   
       
   


 
Anything input you can provide is greatly welecomed.  Thank you in advance.  
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
' 
    ' Generic function for populating the dropdown list.
    ' 
    Public Function FillParameterDDL(ByRef ddList As DropDownList, _
                                     ByVal ddListName As String, _
                                     ByVal parameterValue As String, _
                                     ByVal currentValue As String) As Boolean
 
        Dim dataRS As DataSet
        Dim insertEmptyOption As Boolean
 
        Select Case ddListName
            Case "Evaluation Month"
                dataRS = DA_Assessment.GetEvaluationMonthList(parameterValue)
                insertEmptyOption = True
            Case "Support Area"
                Dim periodId As Integer = Split(parameterValue, "_")(0)
                Dim evaluationMonth As Integer = Split(parameterValue, "_")(1)
                dataRS = DA_Assessment.GetSupportAreaList(CInt(periodId), CInt(evaluationMonth))
                insertEmptyOption = True
            Case "Response"
                dataRS = DA_Assessment.GetResponseList(CInt(parameterValue))
                insertEmptyOption = False
        End Select

Answer : Variable 'dataRS' is used before it has been assigned a value.  A null reference exception could result at runtime.

you are just mentioning you are going to use dataset named dataRS
But you are not been initialized or created! through the following line

Dim dataRS As DataSet

What will happen none of the switch case may not get executed? YOu may know it will not happen, But compiler doesn't!

So try
Dim dataRS As new DataSet
or
Dim dataRS As DataSet = nothing

Regards
Renju
Random Solutions  
 
programming4us programming4us