Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem attempting to fill Datatable from a shared function 1

Status
Not open for further replies.

cdck

Programmer
Nov 25, 2003
281
0
0
US
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:
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
 
I've not got VS on this machine, so I can't check, but you could try something like:

[tt]
Public Sub FillTree(ByVal FromPart As String, [bold]ByVal dt As DataTable[/bold])

[tab]dt.Clear
[tab]......
[tab]......
[tab]da.Fill(dt)
[/tt]

I know I've used something similar in the past.


Hope this helps (or at least points you in the right direction).
 
Thank you, softhemc, it worked beautifully.

Cheryl dc Kern
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top