none
How to filter columns from a dataset? RRS feed

  • Question

  • I have a dataset filled from a XML file with the method : myDataset.LoadFromXMLFile(fileXmlPath);

    There are two tables imported :

    students :
    - id
    - name
    - firstname
    - #professors_id (foreign key to table professors)

    professors :
    - id
    - name
    - firstname

    I want to show in a grid (*) the following columns :
    - name (from students)
    - firstname (from students)
    - name (from professors) (professor responsible of the student <-> foreign key #professors_id)
    - firstname (from professors)

    I want to have a datasource with only those informations. I don't want to filter column in the GUI layer. How to do that?

    - DataView doesn't allow to filter column, only rows.
    - Create a new DataTable?
    - ...

    Thanks for you help!

    (*) : a Xceed WPF DataGrid, not from Microsoft.. it doesn't exist yet

    Monday, November 12, 2007 8:27 AM

All replies

  • Hi,

     

    Just visit this link.

    http://forums.asp.net/p/788821/788917.aspx

    I hope this answer you question.

     

    Regards,

    Manju Sandhu

    Monday, November 12, 2007 10:07 AM
  • So, there is only this tricky solution?!? ADO.NET has not integrated such a function?

    Furthermore, with this solution, do I keep the relational schema integrity?

    For instance :

    I create a new DataTable with your solution :
    - name (from students)
    - firstname (from students)
    - name (from professors) (professor responsible of the student <-> foreign key #professors_id)
    - firstname (from professors)


    I define this table as the dataSource of the User control DataGrid.

    If the user click on the name of a student in
    the DataGrid. How can I look up for the birthday of this student (if the table "students" has a one more field for the student's birthday)?

    students :
    - id
    - name
    - firstname
    - #professors_id (foreign key to table professors)
    - birthday

    professors :
    - id
    - name
    - firstname



    Monday, November 12, 2007 12:05 PM
  • Ok thank you. I had a look and this question popped up..

    If I create a new DataTable and I add unbound DataColumn with Expression property such as "Parent(myRelation).myColumnNeeded".
    myRelation had to be created before between my new table and the table where myColumnNeeded exists..

    To come back to my example :

    So my new Table has :

    - id ->to students table, use in this table as a foreign key described in a DataRelation "newTable_Students" between this new table and the table "students" so as to use the column expression : "Parent(newTable_Students).myColumnNeededInStudentsTable".

    - student_name : Parent(newTable_Students).name
    -
    student_firstname :  Parent(newTable_Students).firstname
    -
    professors_name : Parent(newTable_Students).professors_id.Parent(Students_Professors).name
    - professors_firstname : Parent(newTable_Students).professors_id.Parent(Students_Professors).firstname
    - student_birthday : Parent(newTable_Students).birthday

    Firstly, is it right to do like this?

    And, I still have the column "id" which I don't need for my user control but it seems necessary to keep the relational schema intergrity!
    Monday, November 12, 2007 11:37 PM
  • Hi,

     

    Can you tell me in which control you are showing this data.

     

    Regards,

    Manju Sandhu

     

    Tuesday, November 13, 2007 4:03 AM
  • I use the DataGrid developped by Xceed.
    The control I use shouldn't matter. If you develop an application with a layer architecture, you should be able to connect the control to a datasource without taking care of filtering the data in control GUI! This way doesn't respect the principle of seperation between the different soft layers.
    Tuesday, November 13, 2007 5:29 AM
  • Hi,

     

    You can not remove the linking column from the table. You have to options

     

    1. Create a single datable after joining this two datatables.

    or 2. Do not display that id in design view

     

    Regards,

    Manju Sandhu

     

    Tuesday, November 13, 2007 5:50 AM
  • Well, thank you, but your two options don't satisfy me..
    I think I will develop my own architecture :

    1. I'll parse the dataset and create one object for each data found in the two tables, using those two classes :

    A class : DataProfessors
    + constructor()
    + String name
    + String firstname


    A class : DataStudents
    + constructor(DataProfessors ref) //received the DataProfessors argument corresponding to the foreign key
    + String name
    + String firstname
    + Date birthday
    + the foreign key, a reference to the corresponding "DataProfessors" received in the constructor



    No more ids (primary key), because one instance is exclusive and brings the same concept as a primary key.

    2. Create a Collection for the DataStudents instances and for the DataProfessors instances.

    3. Create instances of the following class which allows to choose which attribute we need specifically from the different table

    A class : StudentsProfessorsView
    + constructor(DataStudents) //in the constructor, it will get the values of the four properties through the DataStudents argument received.
    - DataStudents ref //private reference so as to be able to update values <-> the "id", but it is hidden, because declared private
    + String student_name
    + String student_firstname
    + Date student_birthday
    + String professor_name
    + String professor_firstname


    4. Create a Collection for the StudentsProfessorsView instances

    5. Defines the datasource of the control as the Collection of StudentsProfessorsView

    So as to have dynamic update between the properties in (DataStudents <-> StudentsProfessorsView) <-> StudentsProfessorsView, I would add an Observable pattern between those classes (using dependency properties?)


    What do you think of this architecture?
    Tuesday, November 13, 2007 3:34 PM
  • Nobody ?

    Is my idea totally silly? Or am I on a good direction?

    Xelag
    Wednesday, November 14, 2007 7:01 AM
  • You could use XSLT transformation technique as described in next link

     

    http://support.microsoft.com/kb/555267/en-us

     

    But I am not sure if you really need to transform your data. What you have in your DataSet is one thing, but what you present to the client is another one. You could represent only part of the information to the client, hiding some columns in controls. I believe it will be totally acceptable.

     

    Wednesday, November 14, 2007 11:26 AM
    Moderator
  • It is perhaps acceptable, but if you want a correct software architecture, it is not... As said upper, it doesn't respect the separation between data and view because we get data in the view layer that we don't want. The fact to hide them to the user works very well, but personally, it seems to be a tricky solution.

    As a student, I have no boss to make pressure on me... so, I will developp my own architecture even if it takes more time. It will be a good practice.
    Thursday, November 15, 2007 9:57 AM