I have a DataTable in my local tables which I fill successfully from a button-click on a form. I now want the exact same process to fire from another form, so I took the Sub which fills the table and moved it to a shared functions module, which I use to store functions/subs I need to fire from multiple locations. Here's the code:
When I have this code included in the code for the MngPartTree form, it fires fine. However, when I move this code to the ShardFunctions module, Visual Studio throws an error on the LocalInfoTables.TREEpartsTreed.Clear() and da.Fill(LocalInfoTables.TREEpartsTreed) lines, telling me that "Reference to a non-shared member requires an object reference."
Researching this error seems to indicate that I need to declare the datatable within this patch of code to get rid of this error; however, I'm trying to use an existing datable in the project which is viewed through a datarepeater on my form. Is there any way to overcome this, or will I have to include this code in two locations rather than one so that it can fire from the two different forms?
Cheryl dc Kern
Code:
Public Sub FillTree(ByVal FromPart As String)
LocalInfoTables.TREEpartsTreed.Clear()
Dim constr
constr = My.Settings.M2MAydinOther
Dim SQLstring As String
SQLstring = "SELECT PartNo, ParentPart, qty AS PartQty, qtyExt AS PartQtyExt, identifier AS TreeID, TreeLevel FROM SerialPartTrees WHERE (ParentPart = '" & FromPart & "' AND LowerLevel = 'False') OR (TopPart = '" & FromPart & "' AND LowerLevel = 'True') ORDER BY TopPart, ParentPart, PartNo;"
Dim con As System.Data.SqlClient.SqlConnection
con = New System.Data.SqlClient.SqlConnection(constr)
Dim da As System.Data.SqlClient.SqlDataAdapter
da = New System.Data.SqlClient.SqlDataAdapter(SQLstring, con)
da.Fill(LocalInfoTables.TREEpartsTreed)
con.Close()
con.Dispose()
End Sub
When I have this code included in the code for the MngPartTree form, it fires fine. However, when I move this code to the ShardFunctions module, Visual Studio throws an error on the LocalInfoTables.TREEpartsTreed.Clear() and da.Fill(LocalInfoTables.TREEpartsTreed) lines, telling me that "Reference to a non-shared member requires an object reference."
Researching this error seems to indicate that I need to declare the datatable within this patch of code to get rid of this error; however, I'm trying to use an existing datable in the project which is viewed through a datarepeater on my form. Is there any way to overcome this, or will I have to include this code in two locations rather than one so that it can fire from the two different forms?
Cheryl dc Kern