Hello,
I am trying to create a textbox that reads APPLICATION NAME from a table and displays it in the footer of the report.
I have created a class with following code:
Public Class CVA_Rpt
Public Shared Function Get_Config_Item(ByVal Item_name As String) As String
Dim mySelectQuery As String = "SELECT Constant_Value from tbl_CVA_Config Where Constant_Name='" & Item_name & "'"
Dim myConnString As String = ConfigurationManager.ConnectionStrings("CVA_Reporting").ToString()
Dim myConnection As New SqlClient.SqlConnection(myConnString)
Dim myCommand As New SqlClient.SqlCommand(mySelectQuery, myConnection)
myConnection.Open()
Dim myReader As SqlClient.SqlDataReader
myReader = myCommand.ExecuteReader()
' Always call Read before accessing data.
Get_Config_Item = ""
While myReader.Read()
Get_Config_Item = myReader.GetString(0)
End While
' always call Close when done reading.
myReader.Close()
' Close the connection when done with it.
myConnection.Close()
End Function
Public Shared Function Application_Name() As String
Application_Name = Get_Config_Item("APPLICATION_NAME")
'Application_Name = "CVA Reports"
End Function
End Class
During design time, I enter the following in a textbox of the footer:
= CVA_Reports.CVA_Rpt.Application_Name()
I get the following error when previewing the report:
An error has occurred while processing TextBox 'txtApp_Db_Name':
An error has occurred while executing function App_name(). Check InnerException for further information.
------------- InnerException -------------
Exception has been thrown by the target of an invocation.
------------- InnerException -------------
Object reference not set to an instance of an object.
Note: I testing the CVA_Reports.CVA_Rpt.Application_Name() using a ASP page and it returns the desired value.
How can fix this error ? I have looked everywhere on how to fix this error. I have no clue. Please help. THANK YOU!