Hi, I have a DB connection that works within a class. What I would like to do is be able to create a class with the connection in it (myClass) and reference that connection whenever I need it.
I have the following that works:
'Uses this connection to access TCIS database
Dim Conn As New SqlClient.SqlConnection
Dim dt As New DataTable()
Conn.ConnectionString = "Server=myServer;Database=myDB; Integrated Security=SSPI;"
'Insert code to process data.
Dim sqlCmd As New SqlCommand("sp_mySproc", Conn)
Dim sqlDa As New SqlDataAdapter(sqlCmd)
Dim i As Integer = 0
For i = 0 To dt.Rows.Count - 1
Catch ex As Exception
MessageBox.Show(ex.Message, "Warning Message", MessageBoxButtons.OK)
That works fine but I do not want to write this out everytime I need to access the DB. What I now need to do is be able to reference the above code residing in the myClass Class.
I created the myClass class and tried calling the connection from my Windows form like so:
Dim nmyClass As New myClass
Dim sqlCmd As New SqlCommand("sp_mySproc", nmyClass.SqlCon)
But I get a squiggly line under nmyClass.SqlCon
"Expression does not produce a value".
Can anyone tell me where I am going wrong? Thanks!