Using database views with DataSets RRS feed

  • Question

  • I noticed that I can add a view to my DataSet the same way I can add a table. I usually do it by dragging the table (or in this case, the view) from the server explorer in visual studio. 

    When I do this, It looks the same as any other table I add this way. Is the behavior the same? If I have a view that, in the database, maps table A to table B through an inner join involving table C. Then when the data from table A, B, and C are loaded into the DataSet, will the view rows automatically populate? My guess is no. But it would be nice :) I'd test this myself but my project is in a pretty unstable state right now. 

    Thanks in advance,
    Wednesday, February 4, 2009 4:23 PM


  • For drag/drop the database view onto the design surface as a DataTable.

    A (DataSet) DataTable is agnostic to the source of the data. 

    The DataAdapter is the component that maps from a DataTable <-> command parameters & results.  The default command generation may have difficulty with some views, but can always write your own SQL for the insert/update/delete commands.

    You can't use a (DataSet) DataView to behave like a database view since it doesn't support projections or join semantics.  A DataView is automatically maintained, when rows are added to the DataTable they do appear in the DataView.

    This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to mark the replies as answers if they help.
    Thursday, February 5, 2009 9:53 PM