in

C1 Community

ComponentOne Community is a free source for developers and help authors to collaborate and communicate.

How to remove tables from a dataset at runtime

Last post 03-25-2008 11:09 AM by rlindsey. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 03-24-2008 5:36 PM

    How to remove tables from a dataset at runtime

    I have some tables included in a dataset that are used for lookups. I have foreign key constraints on some of the child tables that reference these tables. My problem is that when I have finished buiding the dataset I do a .WriteXML and then FTP that outut to a mainframe and some of the lookup tables I want to remove are big, and the mainframe doesn't need them.

     I have been able to remove what I think are all the relationships and constraints associated with these tables but when I run the program and call StorageChangeEnd, an exception is thrown saying "Property not accessible because 'Cannot have a relationship between tables in different DataSets.'.".

    I don't know where to look because the message gives no indication as to the name of the offending relationship or the table. Following is a code snippet:

    dsProfile.StorageChangeBegin()

    With dsProfile.StorageDataSet

    .EnforceConstraints = False

    .Tables("tblProfileSourceCodes").Constraints.Clear()

    .Tables("tblProfileSourceTypes").Constraints.Clear()

    .Tables("tblProfilePPISegment").Constraints.Clear()

    .Tables("tblProfileFloatSegment").Constraints.Clear()

    .Tables("tblProfileProcessTimeSlot").Constraints.Clear()

    .Tables("tblProfileDepositTimeSlot").Constraints.Clear()

    .Tables("tblProfileProducts").Constraints.Clear()

    .Tables("tblProfileSourceCodes").ParentRelations.Remove("tblProductionSourceCodes - tblProfileScourceCodes")

    .Tables("tblProfileSourceTypes").ParentRelations.Remove("tblProductionSourceTypes - tblProfileSourceTypes")

    .Tables("tblProfilePPISegment").ParentRelations.Remove("tblProductionSegment - tblProfilePPISegment")

    .Tables("tblProfileFloatSegment").ParentRelations.Remove("tblProductionSegment - tblProfileFloatSegment")

    .Tables("tblProfileProducts").ParentRelations.Remove("tblProductinProducts - tblProfileProducts")

    RemoveTable(dsProfile.StorageDataSet, "tblProductionSourceCodes")

    RemoveTable(dsProfile.StorageDataSet, "tblProductionSourceTypes")

    RemoveTable(dsProfile.StorageDataSet, "tblProductionProducts")

    RemoveTable(dsProfile.StorageDataSet, "tblProductionSegment")

    Dim i As Integer = .Relations.Count - 1

    While i >= 0

    If .Relations.Item(i).RelationName.StartsWith("tblProducti") Then

     .Relations.Remove(.Relations.Item(i).RelationName)

    End If i -= 1

    End While

    '.Relations.Remove("tblProductionBank - tblProfileProcessTimeSlot")

    '.Relations.Remove("tblProductionBank - tblProfileDepositTimeSlot")

    'RemoveTable(dsProfile.StorageDataSet, "tblProductionBank")

    End With

    '---------------------------------------------------

    ' Now tell the C1DataSet we're finished changing the

    ' underlying storage

    '---------------------------------------------------

    dsProfile.StorageChanged(True)

    dsProfile.StorageChangeEnd()

    dsProfile.WriteXml(sPath & sFileName)

     

    Private Sub RemoveTable(ByVal ds As DataSet, ByVal tblName As String)
    With ds

    .Tables(tblName).ChildRelations.Clear()

    .Tables(tblName).Constraints.Clear()

    .Tables(tblName).ParentRelations.Clear()

    .Tables.Remove(tblName)

    End With

    End Sub

  • 03-25-2008 3:38 AM In reply to

    Re: How to remove tables from a dataset at runtime

    Hi,

    This is a very hard way to clear lookup tables. Have you tried to use a simple way?
    For example:

    dsProfile.Clear(New String() {"tblProductionSourceCodes", "tblProductionSourceTypes", _
    "tblProductionProducts", "tblProductionSegment", ...})

    As the general rule, it is better to work with C1 schema objects, such as
    dsProfile.DataSetDefs, dsProfile.Tables, dsProfile.Relations instead of modifing
    the underlying ADO.NET structures.

    Regards,

    -Andrey
  • 03-25-2008 9:42 AM In reply to

    Re: How to remove tables from a dataset at runtime

    Andrey,

    Thanks for the quick response. I tried that method, which does look a lot easier but... the Clear method does not have an overload that accepts arguments. I suspect that I will have problems with that method, unless I did something to remove the foreign key references.

    Thanks

    Ramsey

  • 03-25-2008 10:52 AM In reply to

    Re: How to remove tables from a dataset at runtime

    Hi Ramsey,

    > I tried that method, which does look a lot easier but... the Clear
    > method does not have an overload that accepts arguments.

    The overloaded Clear method with the arguments was added in build
    2.0.20073.192. What's your build number?

    > I suspect that I will have problems with that method, unless I did
    > something to remove the foreign key references.

    If there will be any problems with the foreigh key constraints try
    to set dsProfile.EnforceConstraints to False (please note, this is
    not the same as dsProfile.StorageDataSet.EnforceConstraints,
    which does not affect the internal dataset).

    Regards,

    -Andrey
  • 03-25-2008 11:09 AM In reply to

    Re: How to remove tables from a dataset at runtime

    Andrey,

    Thanks to your suggestion, I did find a better way to get it done.

    I like your product and have een using it for a couple of years now. I would like to offer some constructive criticism. The documentation on the ComponentOne .Net components is so sparse that makes it difficult to effectively use the product. It is easier to understand the underlying ADO .Net features because they are better documented but using them directly always seems to have some idiosyncrasies.

    Thanks again,

    Ramsey

Page 1 of 1 (5 items)
Contact ComponentOne: 1.800.858.2739 ©1987-2008 ComponentOne LLC All Rights Reserved.