This is a migrated thread and some comments may be shown as answers.

a Datatable named '' already belongs to this dataset

1 Answer 662 Views
Grid
This is a migrated thread and some comments may be shown as answers.
byoung
Top achievements
Rank 1
byoung asked on 28 Dec 2012, 08:04 PM
"a Datatable named 'table' already belongs to this dataset" is the error I am getting in a message box on my page. Here is the scenario of what is going on. I am saving the users grouped columns in my database. Upon reentering the page I pull from the database and regroup the grid using the stored values. Example of stored value: Balance Type|balance_type - First item is the name I use to display and the second is the actual field name that we want to group on. This works beautifully. They can save this and renter the grid and the settings is there. BUT!!! When the user selects to change the grid page size is when it generates the above error. I cannot determine where this is happening or why.

I am using needdatasource to bind my data from the SQL server and settting the grids settings after I populate the grid. I only get the settings from the database on the first load of the page because I don't want to stomp on the users changes every time they do something that might cause a postback to the page, that would be annoying.

So any ideas on what this is or why it is happening would be greatly appreciated.

1 Answer, 1 is accepted

Sort by
0
byoung
Top achievements
Rank 1
answered on 31 Dec 2012, 02:41 PM
Well again I have figured out my issue before getting a response to these posts. But in the interest of other users that may come across this post I am putting my resolution here in the hopes that it might help them find an answer. 

My issue boiled down to setting the group by programmatically but not setting the select fields portion. I had the GroupByFields being added but not the selectFields. Once I added that piece the error went away. Not sure if this is right or not but it is working for now. I will report back if it proves to not be right upon further testing.

 Dim grpexp As New GridGroupByExpression
            Dim i As Integer
            Dim Groupbyfield As Array = dsGridSettings.Tables(0).Rows(0).Item("group_by_columns").ToString.Split(",")
            Dim fldDetails As Array
            For i = 0 To Groupbyfield.Length - 1
                Dim fldname As New GridGroupByField
                fldDetails = Groupbyfield(i).ToString.Split("|")
                fldname.HeaderText = Trim(fldDetails(0).ToString())
                fldname.FieldName = Trim(fldDetails(1).ToString())
                grpexp.GroupByFields.Add(fldname)
                grpexp.SelectFields.Add(fldname)
            Next
            Grid.MasterTableView.GroupByExpressions.Add(grpexp)
Tags
Grid
Asked by
byoung
Top achievements
Rank 1
Answers by
byoung
Top achievements
Rank 1
Share this question
or