Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 25th, 2004, 07:39 AM
Authorized User
 
Join Date: Nov 2004
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default Question: DataView and DataTable

Hi,

When I bind a DataTable to DataView, I can sort it, etc. When I delete or update a row in DataView it gets deleted or updated as well in its bound DataTable. Then why instead of adding sorting methods to DataTable object , Microsoft has choosen to create a DataView object?

Thanks in advance.

 
Old November 26th, 2004, 01:29 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 449
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to r_ganesh76
Default

DataViews correspond to the views in the database and the DataTable corresponds to the tables in the Database. The view can be derived from a DataTable and helps to have a different representation of the table.

Regards
Ganesh
 
Old December 3rd, 2004, 01:11 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Ganesh,

That is incorrect. DataView has nothing to do with what database "views" like in MSSQL. I think the intent is that a DataView is a "view" of the data in the source DataTable. The DataView of a DataTable provides the sorting and filtering capabilities for the underlying data that lives in the DataTable.
 
Old December 6th, 2004, 07:44 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 449
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to r_ganesh76
Default

Sorry Peter for the wrong post.

I was taking about the similarity of usage of these two objects. the dataViews can be sorted representation of the DataTable. Correct me if I am wrong.

Regards
Ganesh
 
Old December 19th, 2004, 01:54 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Ganesh,

Yes, you're correct.

A DataTable is like a database table and a DataView is like a database view. So they are functionally the same in that the DataTable holds the actual data while the DataView provides a filtered and/or sorted view of that data.
 
Old December 28th, 2004, 08:28 PM
Authorized User
 
Join Date: Jul 2004
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have a similar question. I have some data returned from a database in a DataSet. I want to sort the data in the dataview, but don't see the data being sorted after I call the sort method on the dataview. The data is sorted is the DataGrid OK, but how do I access the rows in the dataview to see the data has been sorted? Here is my code. Thank you.

DataSet ds = new DataSet();
ds = GetProceedings(currentUser, ddlTime, ddlRoom, strJudge);
if (ds != null)
    {
    DataView dvSearchResults = ds.Tables[0].DefaultView;
    DataRow row = dvSearchResults.Table.Rows[0];
    string test = row["PersonName"].ToString();

    dvSearchResults.Sort = "CaseNumber ASC";
    row = dvSearchResults.Table.Rows[0];
    test = row["PersonName"].ToString();
 
Old December 29th, 2004, 03:15 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

pbyrum-

When you call "<dataview>.Table.Rows[n]" you are calling row n of the original source table for the dataview, not the row of the view itself.

The Dataview class has an indexer which returns a DataRowView object for the row of the data view. So you should be able to do this:

DataRowView row = dvSearchResults[0];





Similar Threads
Thread Thread Starter Forum Replies Last Post
Datagrid or Dataview cp75 Beginning PHP 2 September 26th, 2008 10:56 AM
dataview Yasho VB.NET 2002/2003 Basics 1 May 28th, 2007 03:40 AM
Sorting With dataView anubhav.kumar ADO.NET 1 March 17th, 2005 05:06 AM
Datatable/DataView --> DataAdapter - ThX ! ank2go ADO.NET 4 April 28th, 2004 09:32 AM
DataView vivi C# 4 November 10th, 2003 01:15 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.