Problem accessing value returned from Function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Orbie
    New Member
    • Nov 2009
    • 7

    Problem accessing value returned from Function

    Hi Guys,

    I'm new to VB.NET and want to parameterise the SQL Connection Strings in my VB.NET App. I've added a function to my Main Form to retrieve the App.config File like:

    Code:
    Imports System.Configuration
    Imports System.Configuration.ConfigurationSettings
    
    Public Class MainMenu
    
        Public Function getConnStr() As String
            Dim connections As ConnectionStringSettingsCollection = ConfigurationManager.ConnectionStrings
            Dim constr As String = ""
            constr = connections("Data_Connection").ConnectionString
            Return constr
        End Function
    In my other forms when i want to reference the Connection String, i get an error saying getConnStr is not declared?

    Code:
       Private Sub UpdDept_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Try
                myconnection = New SqlConnection(getConnStr()) <=============
                Dim mycommand As New SqlCommand()
    Any ideas why i get this when i've declared the Function as Public?
  • sashi
    Recognized Expert Top Contributor
    • Jun 2006
    • 1749

    #2
    Hi Orbie,

    Kindly modify your code segment as below;

    Code:
      myconnection = New SqlConnection(getConnStr.ToString)

    Comment

    Working...