Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

what's the Difference between DataView and DataTable?

Answer Posted / rajesh kumar chekuri

DataTable: Represents one table in-memory
DataView:: Represents a customized view of a DataTable for
sorting, filtering, searching, editing, and navigation.
See the following example u can get Better idea...

// Create a new DataTable.
System.Data.DataTable table = new
DataTable("Customers");
// Declare variables for DataColumn and DataRow objects.
DataColumn column;
DataRow row;

// Create new DataColumn, set DataType,
// ColumnName and add to DataTable.
column = new DataColumn();
column.DataType = System.Type.GetType("System.String");
column.ColumnName = "ID";
column.ReadOnly = true;
column.Unique = true;
// Add the Column to the DataColumnCollection.
table.Columns.Add(column);


// Create second column.
// Add the column to the table.
table.Columns.Add("FirstName",
System.Type.GetType("System.String"));

// Add the column to the table.
table.Columns.Add("LastName",
System.Type.GetType("System.String"));

// Make the ID column the primary key column.
DataColumn[] PrimaryKeyColumns = new DataColumn[1];
PrimaryKeyColumns[0] = table.Columns["id"];
table.PrimaryKey = PrimaryKeyColumns;


// add new datarow by adding the values
table.Rows.Add("C101", "Rajesh", "Kumar");
table.Rows.Add("C102", "Fareed", "sk");
table.Rows.Add("C103", "Rajesh", "Raji");

//Sort and display
DataView view = new DataView(table);
view.Sort = "LastName ASC, FirstName ASC";

// assing ur gridview to dataview
GridView1.DataSource = view;
GridView1.DataBind();

Is This Answer Correct ?    18 Yes 9 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do I do implement a assert?

924


can you declare an override method to be static if the original method is not static?

955


What are custom attributes in c#?

834


Why is c# better than java?

955


What is ienumerable t in c#?

816


What is asp net c# corner?

1254


What is javascriptserializer c#?

936


Which is the base class in c#?

868


What is difference between singleton and static class in c#?

880


Can we maintain state in webservice?

919


If you want to convert a base type to a derived type, what type of conversion do you use?

884


Explain the difference between class and interface in .net?

815


What is the role of the datareader class in ado.net connections?

852


Can you declare struct members as protected?

855


Differentiate between object pooling and connection pooling in c#?

934