In my vb project, I have an mdi parent form to open other forms. On one form I have a datagridview displaying a table that I made in sql server. The data loads fine if I set up the connection locally (on the form load with the DGV), but I was told to make the connection global to keep it simpler and stop it getting a bit confusing. I added the code to the mdi form, as below.
Public Class mdi1
Dim con As inifile = New inifile()
Dim constr = con.readconnectionstring()
constr is not declared, it may be inaccessible due to its protection level
As you appear to be a beginner I will try to tell you how to get this working, rather than best practise.
ensure your constr is accessible from anywhere by defining it in your MDI form as
Public constr = con.readconnectionstring()
Now you can access this anywhere by using the fully qualified variable name:
Best practise would be probably to store this in its own class rather than the MDI form