Solved

Can't figure out cause of warning

Posted on 2011-03-15
2
333 Views
Last Modified: 2012-08-13
Hi, there.  I am getting this warning on the code that follows:

Access of shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated.

Private Sub LoadData()
    Dim ds As New DataSet
    Try
        ds = objEngine.SelectRecords("frmDataAssociates")

The underlined code is where the warning is.

Here's the objEngine.SelectRecords() code:

Public Shared Function SelectRecords(ByVal formName As String, Optional ByVal mTab As Integer = 0) As DataSet
        Dim mConnection As OleDbConnection = GetConnection()
        Dim mConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\CLRS\CLRS.mdb"
        Dim mDataSet As New DataSet
        Dim mAdapter As OleDbDataAdapter

        Dim str As String = ""
        Dim tableName As String = ""
        Dim b As New HeaderDB
        Dim objHeader As New Header
        Try
            objHeader = b.Load()
            Select Case formName
                Case "frmSetup"
                    Select Case mTab
                        Case 0, 4 ' Current Month and System
                            str = "SELECT CurrentMonthName,CurrentYear,LegacyCO,Region,RegionPresident,GeneralManager,Manager "
                            str &= "FROM Header;"
                            tableName = "Header"
                        Case 1 ' Stores
                            str = "SELECT StoreID,StoreAbbreviation,StoreState,StoreName "
                            str &= "FROM Stores "
                            str &= "ORDER BY StoreState,StoreName;"
                            tableName = "Stores"
                        Case 2 ' Associates
                            str = "SELECT AssociateID,StoreName,AssociateName "
                            str &= "FROM Associates "
                            str &= "ORDER BY StoreName,AssociateName;"
                            tableName = "Associates"
                        Case 3 ' Products
                            str = "SELECT ProductID,ProductName,ProductType "
                            str &= "FROM Products "
                            str &= "ORDER BY ProductType,ProductName;"
                            tableName = "Products"
                    End Select

                Case "frmDataStores"
                    str = "SELECT  RecordID, CurrMonthName, CurrYear, StoreName, ProductName, Target, Actual, PercentValue "
                    str &= "FROM DataStores "
                    str &= "WHERE (CurrMonthName = '" & objHeader.CurrentMonthName & "') "
                    str &= "AND (CurrYear = " & objHeader.CurrentYear & ") "
                    str &= "ORDER BY StoreName,ProductName;"
                    tableName = "DataStores"

                Case "frmDataAssociates"
                    str = "SELECT RecordID,CurrMonthName,CurrYear,StoreName,AssociateName,ProductName,Target,Actual,PercentValue "
                    str &= "FROM DataAssociates "
                    str &= "WHERE (CurrMonthName = '" & objHeader.CurrentMonthName & "') "
                    str &= "AND (CurrYear = " & objHeader.CurrentYear & ") "
                    str &= "ORDER BY StoreName,AssociateName,ProductName;"
                    tableName = "DataAssociates"

                Case "frmDataTraffic"
                    str = "SELECT TrafficID,CurrMonthName,CurrYear,StoreName,Traffic "
                    str &= "FROM DataTraffic "
                    str &= "WHERE (CurrMonthName = '" & objHeader.CurrentMonthName & "') "
                    str &= "AND (CurrYear = " & objHeader.CurrentYear & ") "
                    str &= "ORDER BY StoreName;"
                    tableName = "DataTraffic"

            End Select
            mConnection.Open()
            mDataSet = New DataSet
            mAdapter = New OleDbDataAdapter(str, mConnectionString)
            mAdapter.Fill(mDataSet, tableName)
        Catch ex As Exception
            ShowError(ex, "DBEngine.SelectRecords", Err.Number, str)
        Finally
            mConnection.Close()
        End Try
        Return mDataSet
    End Function

Open in new window


The code works without error, but I get the warning everytime objEngine.SelectRecords is called.  I hope this is enough information to help you figure out the problem.  Thanks so much.
0
Comment
Question by:Agent909
2 Comments
 
LVL 13

Accepted Solution

by:
gamarrojgq earned 500 total points
ID: 35144267
Hi,

A shared method is not accessed via an object instance like a regular method, but rather is accessed directly from the class

Probably objEngine is an instance of a class, so, to avoid the warning, use the class to call your shared function.

Lets say that your class name is MyClass, then instead of instance the class you call the method directly like this

ds = MyClass.SelectRecords("frmDataAssociates")
0
 
LVL 1

Author Closing Comment

by:Agent909
ID: 35144294
That worked!  Thank you!
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question