editing a Data set in Code

Discussion created by arash.khoddamy on May 8, 2009
Latest reply on Apr 18, 2011 by RJKSolutions

I am trying edit tags of a dataset in 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