none Dataview troubles RRS feed

  • Question

  • I have a shared Dataset in my application define in a class. the Dataset can be accessed by many other classes each adding it's own configuration data to the dataset. The Dataset serves as an in memory database of configuration and validation tables.

    The problem I'm having is when a second instance tries to access the data table default view, I get a row count of 0 yet the table has 8 rows.

    Here is how the dataset is define.

    Public Class clsConfig

      Public Shared dsConfig As DataSet = New DataSet("Support Tables")

    End Class

    I have confirmed that from instance to instance the data table is loaded and has rows. The table is not deleted between the instances either.

    In my Class I call clsMenu i verify if the table is loaded and then try to access the dataview but I get index out of range, which is because the count of rows in the view is 0. So what am I doing wrong?

    Here is the code that sets thing up

    <ComClass(clsMenu.ClassId, clsMenu.InterfaceId, clsMenu.EventsId)> _
    Public Class clsMenu
    #Region "COM GUIDs"
      ' These GUIDs provide the COM identity for this class and its COM interfaces. 
      ' If you change them, existing clients will no longer be able to access the class.
      Public Const ClassId As String = "a6b73838-0768-409e-97f8-a9d7aa835abe"
      Public Const InterfaceId As String = "e8e2ba23-39eb-4e18-a9a5-f4fa52c2a483"
      Public Const EventsId As String = "24c098f1-3392-4a9e-9072-6f3b7cabb5d0"
    #End Region
      Private Shared mbMenuIsLoaded As Boolean = False
      Private msTables() As String = {"Menu"}
      Private msFiles() As String = {"Menus.XML"}
      Private sBaseMenu As String = ""
      Private iBaseMenu As Integer = -99
      Public Enum MenuActionTypes
        DisplayMenu = 1
        RunSub = 2
        EditMenu = 3
        EditDBF = 4 'Parm5 = Path, 
        'If path starts With $ Then keyword follows:
        '(L)ocal,(S)hared,(A)lternate (first Char Is checked)
      End Enum
      Public Sub New() 'Required for COM Interface
        Dim eResult As clsConfig.eConfigStates
        eResult = oConfig.CheckAndLoadConfigFile(ClassId)
        Select Case eResult
          Case clsConfig.eConfigStates.VaildPathOnly
          Case clsConfig.eConfigStates.ValidPathAndName, clsConfig.eConfigStates.ConfigLoaded
            'no action required
          Case Else 'otherwise we have a system issue report it
            Throw New clsMenuDataFileException("New", "Configuration file not loaded: " & eResult.ToString)
        End Select
        mbMenuIsLoaded = oConfig.LocateLoadSupportFile(msTables(0), msFiles(0)) 'only 1 element in the arrays
        Dim tview As DataView = clsConfig.dsConfig.Tables(msTables(0)).DefaultView
    'while debugging first instance is good, use quickview confirms this.
    'Second instance quick view shows Count = 0?
    console.writeline(tview(0)("Descript")) 'throws exception on second instance
        If mbMenuIsLoaded And IsBlankString(tview.Sort) Then 'If data loaded ensure sort order
          tview.Sort = "MenuID ASC, OptID ASC"
          sBaseMenu = tview(0)("Descript")
          iBaseMenu = tview(0)("MenuID")
        End If
      End Sub
      ''' <summary>
      ''' Display a menu of actions
      ''' </summary>
      ''' <param name="MenuId">Menu ID number</param>
      ''' <returns>String of selection: format Action|Parm1|Parm2|Parm3|Parm4|</returns>
      Public Function ShowMenu(ByVal MenuId As Integer) As String
        Return Nothing
      End Function
    End Class

    Tuesday, June 7, 2016 1:22 PM


All replies

  • Hi Mudoch2505,

    According to your code snippet, it seems ok. Could you please provide a simple demo and related test code about issue, I try to reproduce your issue on my side and try to find a solution to resolve it.

    In addition, I would suggest that you could do a judgement above this line, check if the count of tview is 0, if it is 0, please assign the dsConfig from database (or somewhere) again.

    console.writeline(tview(0)("Descript")) 'throws exception on second instance

    Best regards,

    Cole Wu

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, June 8, 2016 1:57 AM
  • I'm not sure what you mean by first instance and second instance, but you might what to try to *NOT* use the DefaultView. So, instead of this:

    Dim tview As DataView = clsConfig.dsConfig.Tables(msTables(0)).DefaultView

    Try it like this (I might screw up the VB syntax, but you should get what I mean):

    Dim tview As New DataView(clsConfig.dsConfig.Tables(msTables(0)))

    ~~Bonnie DeWitt [C# MVP]

    Sunday, June 12, 2016 4:58 PM