Skip to main content

Posts

Showing posts from May, 2011

c# - How to create a DataTable from a DataView

DataView ToTable() method .Net framework's DataView represents a data bindable, customized view of a DataTable for filtering, sorting, searching, editing, and navigation. DataView does not store any data, it represents a connected view of its corresponding DataTable. DataTable represents one table of in-memory data. DataView ToTable() method has four overloaded methods, those are ToTable(), ToTable(String), ToTable(Boolean, String[]), and ToTable(String, Boolean, String[]). DataView ToTable() method creates and returns a new DataTable based on rows in an existing DataView. This method return value type is System.Data.DataTable which represents a new DataTable instance that contains the requested rows and columns. This method returned DataTable contains the same columns as the input table. Returned DataTable name is also the same as the source DataTable. DataView ToTable(String) overloaded method also creates and returns a DataTable bas...

c# - How to add a new row to the DataView

Add a new row to a DataView The DataView is a customized view of a DataTable for sorting, filtering, searching, editing, and navigation. The DataView does not store data. When the asp.net developer changes the DataView's data that will affect the DataTable. But when they change the DataTable's data that will affect all associated DataViews. The DataView is much like a database view. The following asp.net c# tutorial code demonstrates how we can add a new row to a DataView. Here we used the DataView class AddNew() method to add a new row to a DataView instance. The DataView class AddNew() method adds a new row to the DataView. The AddNew() method returns a new DataRowView object. The DataRowView class represents a customized view of a DataRow. After adding the row to the DataView we can insert data into the row for specified columns. The DataRowView class EndEdit() method commits changes to the underlying DataRow and ends the edit...

c# - How to create a DataTable with distinct rows from a DataView

Create a DataTable with distinct rows from a DataView The DataView is a customized view of a DataTable for sorting, filtering, searching, editing, and navigation. The DataView does not store data. When the asp.net developer changes the DataView's data that will affect the DataTable. But when they change the DataTable's data that will affect all associated DataViews. The DataView is much like a database view. The DataTable class represents one table of in-memory data. The DataTable is a central object in the ADO.NET library. The DataSet and DataView objects use DataTable.The following asp.net c# tutorial code demonstrates how we can create a DataTable with distinct rows from a DataView. Here we used the DataView class ToTable() method’s specified overload to create a DataTable with distinct rows from a specified DataView instance. The DataView class ToTable() method creates and returns a new DataTable based on rows in an existing DataV...

c# - How to sort a DataView

DataView Sort Property .NET framework's DataView represents a data bindable, customized view of a DataTable for sorting, filtering, searching, editing, and navigation. DataView class exists in System.Data namespace. The DataView Sort property allows us to get or set the sort column or columns and sort order for the DataView. DataView Sort property value data type is a String. This value represents a String that contains the column name followed by ASC ascending or DESC descending. If we want to sort DataView by multiple columns, we need to separate multiple columns by commas. By default, columns are sorted in ascending order. We can implement the DataView Sort property value as "BookName Desc" for single-column sorting or "Country ASC, City DESC" for multiple columns sorting. The following ADO.NET C# example code demonstrates to us how can we sort DataView data programmatically at run time in an ASP.NET application....

c# - How to get the source table of a DataView

Get the source table of a DataView The DataView is a customized view of a DataTable for sorting, filtering, searching, editing, and navigation. The DataView does not store data. When the asp.net developer changes the DataView's data that will affect the DataTable. But when they change the DataTable's data that will affect all associated DataViews. The DataView is much like a database view. The following asp.net c# tutorial code demonstrates how we can get the source table of a DataView. Here we used the DataView class Table property to get the source DataTable object of a specified DataView instance. The DataView class Table property gets or sets the source DataTable. The Table property value is a DataTable that provides the data for this view. The DataTable also has a DefaultView property which returns the default DataView for the table. The asp.net developers can only set the Table property if the current value is null. The...

c# - How to filter data in a DataView

DataView RowFilter Property .Net framework's DataView represents a data bindable, customized view of a DataTable for sorting, searching, filtering, navigation, and editing. DataView represents a connected view of its corresponding DataTable. DataView does not stroe data. If we change the DataView data, it will affect the DataTable. If we change the DataTable's data, it will affect all associated DataViews. DataView class exists in System.Data namespace. DataView class’s RowFilter property allows us to get or set the expression used to filter which rows are viewed in the DataView. RowFilter property value data type is String which represents a String that specifies how rows are to be filtered. We can assign a RowFilter value as "FirstName = 'Innee'" where 'FirstName' is a column name followed by an operator (=) and a value 'Innee' to filter on. The value must be in quotation marks. The followi...

c# - How to count rows in a DataView

DataView Count Property .NET framework's DataView represents a data bindable, customized view of a DataTable for sorting, searching, filtering, navigation, and editing. The DataView object does not store data but it represents a connected view of its corresponding DataTable. DataView RowFilter property allows us to get or set the expression used to filter which rows are viewed in the DataTable. DataView RowStateFilter property allows us to get or set the row state filter used in the DataView. The DataView Count property allows us to get the number of records (rows) in a DataTable after RowFilter and RowStateFilter have been applied. The Count property value data type is an Int32. This integer value represents the number of records in the DataView. The Count property implements as ICollection.Count. The following ADO.NET C# example code demonstrates to us how can we count a DataView's rows (records) programmatically at run time in...

c# - How to create a DataView

Create a new DataView The DataView is a customized view of a DataTable for sorting, filtering, searching, editing, and navigation. The DataView does not store data. When the asp.net developer changes the DataView's data that will affect the DataTable. But when they change the DataTable's data that will affect all associated DataViews. The DataView is much like a database view. The following asp.net c# tutorial code demonstrates how we can create a new DataView. Here we used the DataView class DataView(DataTable) constructor to create a new instance of the DataView object. The DataView class DataView(DataTable) constructor initializes a new instance of the DataView class with the specified DataTable. The DataView (System.Data.DataTable? table) constructor has a parameter named table. The table parameter is a DataTable to add to the DataView. The DataTable class represents one table of in-memory data. The DataTable is a central obj...

c# - How to merge two DataTables

DataTable Merge() Method .NET framework's DataTable represents one table of in-memory data. DataTable is a central object in the ado.net library. DataSet and DataView both objects use DataTable. The DataTable Merge() method allows us to merge the specified DataTable with the current DataTable. The Merge() method is used to merge two DataTable objects that have largely similar schemas. Child tables are not affected or merged with the current table. If a table has child tables as part of the relationship, each child table must be merged individually. DataTable Merge method is overloaded, those are Merge(DataTable), Merge(DataTable, Boolean), and Merge(DataTable, Boolean, MissingSchemaAction). DataTable Merge(DataTable) overloaded method allows us to merge the specified DataTable with the current DataTable. Merge(DataTable) requires passing a parameter named table. This table parameter value type is System.Data.DataTable which represent...

c# - How to use DataTable Compute method

DataTable Compute() Method .NET framework's DataTable represents one table of in-memory data. The DataTable class exists in the System.Data namespace. DataTable Compute() method allows us to compute the given expression on the current rows that pass the filter criteria. DataTable Compute() method requires passing two parameters named expression and filter. Both parameters value data type are String. The expression parameter represents the expression to compute and the filter parameter represents the filter to limit the rows that evaluate in the expression. DataTable Compute() method return value type is Object which represents an Object, set to the result of the computation. Compute() method return DBNull.Value, if the expression evaluates to null. We can pass the expression parameter value as: "Count(BookName)" where 'BookName' is a column name. "Sum(Quantity * BookPrice)" where 'Qua...

c# - How to copy a DataTable

Copy a DataTable The DataTable class represents one table of in-memory data. The DataTable objects are conditionally case-sensitive. To create a DataTable programmatically the asp.net developers must first define its schema by adding DataColumn objects to the DataColumnCollection. To add rows to a DataTable, the developers must use the NewRow() method to return a new DataRow object at first. The DataTable also contains a collection of Constraint objects that can be used to ensure the integrity of the data. The following asp.net c# tutorial code demonstrates how we can copy a DataTable. Here we used the DataTable class Copy() method to copy a DataTable instance. The DataTable class Copy() method copies both the structure and data for this DataTable. The Copy() method returns a new DataTable. This method returns a new DataTable with the same structure and data as this DataTable. The DataTable Copy() method creates a new DataTable with the ...