4 Replies Latest reply on Apr 18, 2011 9:03 AM by RJKSolutions

    editing a Data set in Code


      I am trying edit tags of a dataset in VB.net and I get the error message that “Data Set has not been opened for modification”. How do I open a dataset to modify it in code?


      Here is my code

      Dim MyDisplay As Display
      Dim MyDatasets As Datasets
      Dim DatasetType As pbDatasetType
      Dim TagList As ArrayList = New ArrayList

      MyDisplay = pbApplication.ActiveDisplay
      MyDatasets = MyDisplay.Datasets

      For Index = 1 To MyDatasets.Count
          DatasetType = MyDatasets.Item(Index).Type

          SelectCase DatasetType

              Case pbDatasetType.pbDatasetPIExpression

                  Dim ExDs As PIExpressionDataset = MyDatasets.Item(Index)
                  Dim NewEx AsString

                  If ExDs.ServerName = OldServerName Then
      NewEx = ExDs.Expression
                      TagList = ParseTagNames(ExDs.Expression)
                      ExDs.ServerName = NewServerName

                      ForEach Tagname AsStringIn TagList
                          TagCount = TagCount + 1
                          NewEx = NewEx.Replace(Tagname, NewTagName)
                          ExDs.Expression = ExDs.Expression.Replace(Tagname, NewTagName)
      End If

              Case pbDatasetType.pbDatasetPISummary

                  Dim SumDs As PISummaryDataset = MyDatasets.Item(Index)

                  If SumDs.ServerName = OldServerName Then
                      TagCount = TagCount + 1
                      SumDs.ServerName = NewServerName
                      SumDs.TagName = NewTagName
                  End If

              End Select
          Next Index
      End Sub