DataTables and DataViews in ADO.NET very much similar to SQL Server DataBase tables and View


DataTables in ADO.NET
Datatables are ADO.NET Objects which are just like database tables, wherein one can add columns and rows ..
as we add them in a database. They store data in memory
  DataTable table = new DataTable();
        table.Columns.Add("Dosage", typeof(int));
        table.Columns.Add("Drug", typeof(string));
        table.Columns.Add("Patient", typeof(string));
        table.Columns.Add("Date", typeof(DateTime));
        return table;
DataViews in ADO.NET
Data Views are ado.net Object sused for dynamic viewing of data in a Database and manipulate them as needed .They use operations like filtering, sorting, binding, Editing of data. They can be considered as view of datatable.
Say you want to work on a table in SQL Server Database instead of making any changes in the stored procedure. , we can create a data view and make things work there..
For e.g... Check this C# Code

    DataView DV = new DataView(custDS.Tables["Customer"], 
    "Country = 'USA'", 
    "FirstName", 
    DV.Sort = "FirstName ASC";
 
Here User is a table in database and country and first name are its columns dv.sort will do sorting on FirstName in ascending order ...

No comments:

Post a Comment