none
Can you alias a column name in a Winforms DataView? RRS feed

  • Question

  • I have a DataView that I created from a dataset.  The dataset contains data as a lookup means for many comboboxes.  The DataView will get created for each combobox with the appropriate .RowFilter. 

    Is there a means of aliasing a DataView column?  I have the id column set as my combobox's ValueMember.  This ValueMember will then get sent to the database using a dataadapter CommandBuilder command. 

    The table being updated has a different column name, so I want to alias the id column in the dataview to that the updating table column name, i.e. school_id.

    TIA,

    aj

    Sunday, April 11, 2010 3:45 PM

Answers

  • Hi Alex,

    Yes you have understood the problem correctly.  I have been able to resolve this issue.  The dataview is bound to the combo box as the datasource.    I added a column to datatable in the dataview with the column name I needed and filled it in from the Dataview Id column. CommandBuilder workes as desired. Thanks,

    AJ

    • Marked as answer by ajbailey7 Thursday, April 15, 2010 1:28 AM
    Thursday, April 15, 2010 1:28 AM

All replies

  • You might consider writting your own SQL update command instead of letting CommandBuilder do it.

    Miha Markic [MVP C#] http://blog.rthand.com
    Monday, April 12, 2010 7:03 AM
  • So I take it from your answer that No, a column cannot be given an alias name.  How about through LINQ?  As large as this application is and the time frame ensued, writing update statements is not an option.  Upon Phase II we have it scoped to perform stored procedure updates.

    TIA,

    AJ

    Monday, April 12, 2010 11:43 PM
  • Hi ajbailey,

    Do you mean that you create the DataView with a data table in dataset, and set the dataview as the data source to combobox, then you want to update a different table in database with this dataview using dataadapter?

    Since when you instantiate the commandbulider with dataadapter and use this dataadapter to fill the data table as the source of DataView, the commands being created are related to datatable(which has a ID column as you mentioned). Then you want to update another table with school_id column ?

    Could you provide more information or some sample code? We may find an alternative way for you.

    Please correct me if I misunderstand you. Thank you.

    Best regards,
    Alex Liang


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, April 14, 2010 6:37 AM
    Moderator
  • Hi Alex,

    Yes you have understood the problem correctly.  I have been able to resolve this issue.  The dataview is bound to the combo box as the datasource.    I added a column to datatable in the dataview with the column name I needed and filled it in from the Dataview Id column. CommandBuilder workes as desired. Thanks,

    AJ

    • Marked as answer by ajbailey7 Thursday, April 15, 2010 1:28 AM
    Thursday, April 15, 2010 1:28 AM