How to print foriegn key values in a datatable in a report RRS feed

  • Question

  • Hello friends,

    I am doing a small project using VS express 2010. I am printing a report using my own printing code which is adapted from this link:

    In my dataset there are datables which have foriegn keys, and when I print a report I wish to print foriegn key values looked up from the corresponding table. For example a table 'Trips' contains a foreign key 'TripStatusId' which is a Primary Key in another table named 'TripStatus'. In the table TripStatus there is a field TripStatus for every TripStatusId.

    The way my report is printed works like this. The Trips table is being displayed in a DataGridView. The DataGridView is bound to the Trips datatable through a bindingsource. When the user selects a row and clicks on print button the current selected row i retrieved and passed on to the object which handles the actual printing. While passing the datarow to the printing class I also pass on information about the columns which are to be printed from the row. In the printing class the code iterates over the fields of the datarow passed to it and prints the fields specified by the columns information passed alongwith.

    So now what I can't understand is: How can I print 'TripStatus' instead of 'TripStatusId' in the report. I think that the change has to be done before the selected Trip row is passed onto the Printing Class. But how and where?

    What is the usual way of doing this? Any idea or suggestion would be appreciated.

    Peace, one day.

    Tuesday, May 8, 2012 7:27 PM


All replies

  • Hi Mvstical,

    You need to query this field first. If you didn't query it, you never get it.

    Have a nice day,

    Call me ghost for short, Thanks
    To get the better answer, it should be a better question.

    Thursday, May 10, 2012 7:53 AM
  • Hi,

    you can create an extra expression field in your datatable, that gets its value from a parent column;

    have a look at this example:

    Regards, Nico

    • Marked as answer by mystical5 Thursday, May 10, 2012 1:32 PM
    Thursday, May 10, 2012 7:58 AM
  • @Nico
    Thank you for the the reply. That did the trick. What I did was I added the expression field to the Datatable when they were created. And when I print I just send the expression field to the report class wherever required, leaving out the foreign key field altogether.

    Peace, one day.

    Thursday, May 10, 2012 1:32 PM