[RESOLVED] Why cant sqlConnection and sqlDataAdapter variables be global ?
Hi, :wave:
When I tried to create a global variable of type sqlConnection and sqlDataAdapter, vb 2005 underlines it and says that the "type is not defined".
The 2 declarations are:
Dim myConnection As SqlConnection = New SqlConnection(..........)
Dim myAdapter As SqlDataAdapter = New SqlDataAdapter(......,....)
When they are added as global variables (outside of any private sub), vb 2005 highlights sqlConnection and sqlDataAdapter as errors. But when they are added inside a private sub procedure, like Private Sub Form1_Load, then there is no error.
How come they cant be global variables? I need them to be freely accessed by the various Private Sub procedure inside the Form1 public class.
Re: Why cant sqlConnection and sqlDataAdapter variables be global ?
Shouldn't be much different in 2005.
Dim myConnection As New SqlClient.SqlConnection
Dim myAdapter As New SqlClient.SqlDataAdapter
1 Attachment(s)
Re: Why cant sqlConnection and sqlDataAdapter variables be global ?
You are mistaken. You must be doing something else that you aren't mentioning, like trying to declare them in a file that hasn't imported the appropriate namespace.
Re: Why cant sqlConnection and sqlDataAdapter variables be global ?
I did add the system.data and system.data.sqlclient namespaces.
I've removed the " = new sqlConnection" part and replaced it with dim myconnection as new sqlConnection. It works now :)