SlideShare a Scribd company logo
1 of 23
   DataTable
   DataColumn
   DataRow
   DataView
   DataSet
   The DataTable object represents tabular data as
    rows, columns, and constraints.

   Use the DataTable object to hold data in
    memory while performing disconnected data
    operations.

   Can get a DataTable object by connecting to the
    database and returning table data.
   Can be explicitly created by instantiating the
    DataTable class

   You then add DataColumn objects to the class to
    define the type of data to be held.

   The DataColumn objects also contain constraints.

   Once the DataTable is defined with columns, you
    can add DataRow objects that contain data for the
    table.
private DataTable GetDataTable()
{
    DataTable employee = new DataTable("Employee");
    DataColumn eid = new DataColumn("Eid");
    eid.DataType = typeof(string);
    eid.MaxLength = 10;
    eid.Unique = true;
    eid.AllowDBNull = false;
    eid.Caption = "EID";
    employee.Columns.Add(eid);
    return employee;
}
   DataType
   MaxLength
   Unique
   AllowDBNull
   Caption
   The primary key of a DataTable object consists of
    one or more columns that define data that
    represent a unique identity for each row in the
    data.

employee.PrimaryKey = new DataColumn[] {eid};
   The DataTable object contains a Rows
    collection, which contains a collection of
    DataRow objects.

   You can insert data into the Rows collection by
    using

       Add method on the Rows collection
       Load method on the DataTable object.
DataRow newemployee = employee.NewRow();
newemployee["Eid"] = "123456789A";
newemployee["FirstName"] = "Nancy";
newemployee["LastName"] = "Davolio";
newemployee["Salary"] = 10.00m;
employee.Rows.Add(newemployee);

Or

employee.Rows.Add("987654321X", "Andrew", "Ful
  ler", 15.00m);
employee.LoadDataRow( new object[]
{ "987654321X", "Janet", "Leverling", 20.00m },
LoadOption.OverwriteChanges);

   LoadOption enumeration value that has one of
    the following values:

       OverwriteChanges
       PreserveChanges
       Upsert
   Detached : DataRow is created but not
    added to a DataTable.
   Added : DataRow is added to a DataTable.
   Unchanged : DataRow has not changed
    since the last call to the AcceptChanges
    method. The DataRow changes to this state
    when the AcceptChanges method is called.
   Modified : DataRow has been modified
    since the last time the AcceptChanges
    method was called.
   Deleted : DataRow is deleted using the
    Delete method of the DataRow.
   The AcceptChanges method is used to reset the
    DataRow state to Unchanged.

   After data has been loaded from the database, the
    RowState property of the loaded rows is set to Added.

   Calling AcceptChanges on the DataTable resets the
    RowState of all of the DataRow objects to Unchanged.
   If you modify the DataRow objects, their RowState
    changes to Modified.

   After the changes have been successfully sent to the
    data store by calling the AcceptChanges method the
    RowState changes to Unchanged.
   The Delete method on the DataRow is used to set the
    RowState of the DataRow to Deleted.

   There are many scenarios where you need to undelete a
    DataRow.

   The DataRow object doesn’t have an undelete
    method, but you can use the RejectChanges method to
    perform an undelete that may satisfy some scenarios.
   The DataRow object can hold up to three versions, or copies, of
    the data: Original, Current, and Proposed.

   When the DataRow is created, it contains a single copy of the
    data, which is the Current version.

   When the DataRow is placed into edit mode by executing its
    BeginEdit method, changes to the data are placed in a second
    version of the data, called the Proposed version.

   When the EndEdit method is executed, the Current version
    becomes the Original version, the Proposed version becomes
    the Current version, and the Proposed version no longer exists.


   After EndEdit has completed its execution, there are two
    versions of the DataRow data: Original and Current.
   You often need to create a full copy of a DataTable in
    your application.

   For example, you might want to assign a DataTable
    object to a GridView control to allow a user to edit the
    data, but you also might want to provide a cancel
    button that aborts all changes on the Web page.

   A simple way to implement this functionality is to
    create a copy of your DataTable object and use the copy
    for editing.

   DataTable copy = employee.Copy();
   You often require a copy of the DataTable schema
    without the data.
   You can accomplish this by invoking the Clone method
    on the DataTable.
   Use this method when an empty copy of the DataTable
    is required and to which DataRow objects will be added
    at a later time.

    DataTable clone = employee.Clone();
    clone.ImportRow(employee.Rows[0]);

   The ImportRow method on the DataTable object copies
    a DataRow from a DataTable that has the same schema.
   The DataView object provides a window into a
    DataTable that can be sorted and filtered using the
    Sort, RowFilter, and RowStateFilter properties.

   A DataTable can have many DataView objects assigned
    to it, allowing the data to be viewed in many different
    ways without requiring the data to be reread from the
    database.

   The DataView object also contains the
    AllowDelete, AllowEdit, and AllowNew properties to
    constrain user input as needed.
protected void Button7_Click(object sender, EventArgs e)
{
//get datatable
DataTable employee = GetDataTable();
//sort and display
DataView view = new DataView(employee);
view.Sort = "LastName ASC, FirstName ASC, Salary DESC";
GridView1.DataSource = view;
GridView1.DataBind();
}
Also RowFilter can be set to a SQL WHERE clause without the
   word “WHERE.”
view.RowFilter = "LastName like 'A%' and Salary > 15";
   The DataSet is a memory-based relational
    representation of data and the primary disconnected
    data object.
   The DataSet contains a collection of DataTable and
    DataRelation objects.
private DataSet GetDataSet()
{
DataSet companyData = new DataSet("CompanyList");
DataTable company = companyData.Tables.Add("company");
company.Columns.Add("Id", typeof(Guid));
company.Columns.Add("CompanyName", typeof(string));
company.PrimaryKey = new DataColumn[] { company.Columns["Id"] };
DataTable employee = companyData.Tables.Add("employee");
employee.Columns.Add("Id", typeof(Guid));
employee.Columns.Add("companyId", typeof(Guid));
employee.Columns.Add("LastName", typeof(string));
employee.Columns.Add("FirstName", typeof(string));
employee.Columns.Add("Salary", typeof(decimal));
employee.PrimaryKey = new DataColumn[] { employee.Columns["Id"] };
companyData.Relations.Add(
"Company_Employee",
company.Columns["Id"],
employee.Columns["CompanyId"]);
return companyData;
Label lbl = GetLabel(275, 20);
DataSet companyList = GetDataSet();
DataRelation dr = companyList.Relations["Company_Employee"];
DataRow companyParent = companyList.Tables["company"].Rows[1];
lbl.Text = companyParent["CompanyName"] + "<br />";
foreach (DataRow employeeChild in companyParent.GetChildRows(dr))
{
lbl.Text += "&nbsp;&nbsp;&nbsp;" + employeeChild["Id"] + " "
+ employeeChild["LastName"] + " "
+ employeeChild["FirstName"] + " "
+ string.Format("{0:C}", employeeChild["Salary"]) + "<br />";
}
lbl.Text += "<br /><br />";
DataRow employeeParent = companyList.Tables["employee"].Rows[1];
lbl.Text += employeeParent["Id"] + " "
+ employeeParent["LastName"] + " "
+ employeeParent["FirstName"] + " "
+ string.Format("{0:C}", employeeParent["Salary"]) + "<br />";
DataRow companyChild = employeeParent.GetParentRow(dr);
lbl.Text += "&nbsp;&nbsp;&nbsp;" + companyChild["CompanyName"] + "<br />";
   A DataSet can be serialized as XML or as binary data to
    a stream or file.

   The DataSet can also be deserialized from XML or
    binary data from a stream or file. The serialized data
    can be transferred across a network via many
    protocols, including HTTP.

More Related Content

What's hot

Windows Mobile 5.0 Data Access And Storage Webcast
Windows Mobile 5.0 Data Access And Storage WebcastWindows Mobile 5.0 Data Access And Storage Webcast
Windows Mobile 5.0 Data Access And Storage WebcastVinod Kumar
 
Graph db as metastore
Graph db as metastoreGraph db as metastore
Graph db as metastoreHaris Khan
 
Ado.net session05
Ado.net session05Ado.net session05
Ado.net session05Niit Care
 
Data management with ado
Data management with adoData management with ado
Data management with adoDinesh kumar
 
Database connectivity to sql server asp.net
Database connectivity to sql server asp.netDatabase connectivity to sql server asp.net
Database connectivity to sql server asp.netHemant Sankhla
 
Databind in asp.net
Databind in asp.netDatabind in asp.net
Databind in asp.netSireesh K
 
Google Chart Tools
Google Chart Tools Google Chart Tools
Google Chart Tools Kanika Garg
 
ASP.Net 3.5 SP1 Dynamic Data
ASP.Net 3.5 SP1 Dynamic DataASP.Net 3.5 SP1 Dynamic Data
ASP.Net 3.5 SP1 Dynamic Datamicham
 
PATTERNS08 - Strong Typing and Data Validation in .NET
PATTERNS08 - Strong Typing and Data Validation in .NETPATTERNS08 - Strong Typing and Data Validation in .NET
PATTERNS08 - Strong Typing and Data Validation in .NETMichael Heron
 

What's hot (19)

Grid Vew Control VB
Grid Vew Control VBGrid Vew Control VB
Grid Vew Control VB
 
GRID VIEW PPT
GRID VIEW PPTGRID VIEW PPT
GRID VIEW PPT
 
Windows Mobile 5.0 Data Access And Storage Webcast
Windows Mobile 5.0 Data Access And Storage WebcastWindows Mobile 5.0 Data Access And Storage Webcast
Windows Mobile 5.0 Data Access And Storage Webcast
 
Viewpic
ViewpicViewpic
Viewpic
 
Graph db as metastore
Graph db as metastoreGraph db as metastore
Graph db as metastore
 
Charting with Google
Charting with GoogleCharting with Google
Charting with Google
 
Ado.net session05
Ado.net session05Ado.net session05
Ado.net session05
 
MongoDB
MongoDBMongoDB
MongoDB
 
Data management with ado
Data management with adoData management with ado
Data management with ado
 
Android - Saving data
Android - Saving dataAndroid - Saving data
Android - Saving data
 
Database connectivity to sql server asp.net
Database connectivity to sql server asp.netDatabase connectivity to sql server asp.net
Database connectivity to sql server asp.net
 
Databind in asp.net
Databind in asp.netDatabind in asp.net
Databind in asp.net
 
Backendless apps
Backendless appsBackendless apps
Backendless apps
 
2310 b 10
2310 b 102310 b 10
2310 b 10
 
Google Chart Tools
Google Chart Tools Google Chart Tools
Google Chart Tools
 
Getting Started with MongoDB
Getting Started with MongoDBGetting Started with MongoDB
Getting Started with MongoDB
 
ASP.Net 3.5 SP1 Dynamic Data
ASP.Net 3.5 SP1 Dynamic DataASP.Net 3.5 SP1 Dynamic Data
ASP.Net 3.5 SP1 Dynamic Data
 
FiletodbAdapters
FiletodbAdaptersFiletodbAdapters
FiletodbAdapters
 
PATTERNS08 - Strong Typing and Data Validation in .NET
PATTERNS08 - Strong Typing and Data Validation in .NETPATTERNS08 - Strong Typing and Data Validation in .NET
PATTERNS08 - Strong Typing and Data Validation in .NET
 

Similar to DataTable, DataSet, and DataView objects in .NET

1 MVC – Ajax and Modal Views AJAX stands for Asynch.docx
1  MVC – Ajax and Modal Views AJAX stands for Asynch.docx1  MVC – Ajax and Modal Views AJAX stands for Asynch.docx
1 MVC – Ajax and Modal Views AJAX stands for Asynch.docxhoney725342
 
Configuring Data Binding part2 ABTO Software Lecture Korotchyn
Configuring Data Binding part2 ABTO Software Lecture KorotchynConfiguring Data Binding part2 ABTO Software Lecture Korotchyn
Configuring Data Binding part2 ABTO Software Lecture KorotchynABTO Software
 
Accessing data with android cursors
Accessing data with android cursorsAccessing data with android cursors
Accessing data with android cursorsinfo_zybotech
 
Detail view in distributed technologies
Detail view in distributed technologiesDetail view in distributed technologies
Detail view in distributed technologiesjamessakila
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studioAravindharamanan S
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studioAravindharamanan S
 
Introduction to ADO.NET
Introduction to ADO.NETIntroduction to ADO.NET
Introduction to ADO.NETrchakra
 
ASP.NET Session 13 14
ASP.NET Session 13 14ASP.NET Session 13 14
ASP.NET Session 13 14Sisir Ghosh
 
Ado.Net Architecture
Ado.Net ArchitectureAdo.Net Architecture
Ado.Net ArchitectureUmar Farooq
 
Intake 38 data access 5
Intake 38 data access 5Intake 38 data access 5
Intake 38 data access 5Mahmoud Ouf
 
QTP Automation Testing Tutorial 7
QTP Automation Testing Tutorial 7QTP Automation Testing Tutorial 7
QTP Automation Testing Tutorial 7Akash Tyagi
 
I am looking for some assistance with SQLite database. I have tried se.pdf
I am looking for some assistance with SQLite database. I have tried se.pdfI am looking for some assistance with SQLite database. I have tried se.pdf
I am looking for some assistance with SQLite database. I have tried se.pdfConint29
 

Similar to DataTable, DataSet, and DataView objects in .NET (20)

Sql server-function
Sql server-functionSql server-function
Sql server-function
 
1 MVC – Ajax and Modal Views AJAX stands for Asynch.docx
1  MVC – Ajax and Modal Views AJAX stands for Asynch.docx1  MVC – Ajax and Modal Views AJAX stands for Asynch.docx
1 MVC – Ajax and Modal Views AJAX stands for Asynch.docx
 
Chapter 15
Chapter 15Chapter 15
Chapter 15
 
Configuring Data Binding part2 ABTO Software Lecture Korotchyn
Configuring Data Binding part2 ABTO Software Lecture KorotchynConfiguring Data Binding part2 ABTO Software Lecture Korotchyn
Configuring Data Binding part2 ABTO Software Lecture Korotchyn
 
ADO DOT NET
ADO DOT NETADO DOT NET
ADO DOT NET
 
Accessing data with android cursors
Accessing data with android cursorsAccessing data with android cursors
Accessing data with android cursors
 
ADO .Net
ADO .Net ADO .Net
ADO .Net
 
Detail view in distributed technologies
Detail view in distributed technologiesDetail view in distributed technologies
Detail view in distributed technologies
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studio
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studio
 
Ado.net
Ado.netAdo.net
Ado.net
 
Introduction to ADO.NET
Introduction to ADO.NETIntroduction to ADO.NET
Introduction to ADO.NET
 
ASP.NET Session 13 14
ASP.NET Session 13 14ASP.NET Session 13 14
ASP.NET Session 13 14
 
Ado.Net Architecture
Ado.Net ArchitectureAdo.Net Architecture
Ado.Net Architecture
 
ADO.NET
ADO.NETADO.NET
ADO.NET
 
ADO.net control
ADO.net controlADO.net control
ADO.net control
 
Intake 38 data access 5
Intake 38 data access 5Intake 38 data access 5
Intake 38 data access 5
 
ADO.NET
ADO.NETADO.NET
ADO.NET
 
QTP Automation Testing Tutorial 7
QTP Automation Testing Tutorial 7QTP Automation Testing Tutorial 7
QTP Automation Testing Tutorial 7
 
I am looking for some assistance with SQLite database. I have tried se.pdf
I am looking for some assistance with SQLite database. I have tried se.pdfI am looking for some assistance with SQLite database. I have tried se.pdf
I am looking for some assistance with SQLite database. I have tried se.pdf
 

More from aspnet123

Deploying configuring caching
Deploying configuring cachingDeploying configuring caching
Deploying configuring cachingaspnet123
 
Mobile application
Mobile applicationMobile application
Mobile applicationaspnet123
 
Globalization and accessibility
Globalization and accessibilityGlobalization and accessibility
Globalization and accessibilityaspnet123
 
Monitoring, troubleshooting,
Monitoring, troubleshooting,Monitoring, troubleshooting,
Monitoring, troubleshooting,aspnet123
 
Programming web application
Programming web applicationProgramming web application
Programming web applicationaspnet123
 
User controls
User controlsUser controls
User controlsaspnet123
 
Custom controls
Custom controlsCustom controls
Custom controlsaspnet123
 
Web services
Web servicesWeb services
Web servicesaspnet123
 
Working with xml data
Working with xml dataWorking with xml data
Working with xml dataaspnet123
 
Connected data classes
Connected data classesConnected data classes
Connected data classesaspnet123
 
Introducing asp
Introducing aspIntroducing asp
Introducing aspaspnet123
 

More from aspnet123 (12)

Deploying configuring caching
Deploying configuring cachingDeploying configuring caching
Deploying configuring caching
 
Mobile application
Mobile applicationMobile application
Mobile application
 
Profile
ProfileProfile
Profile
 
Globalization and accessibility
Globalization and accessibilityGlobalization and accessibility
Globalization and accessibility
 
Monitoring, troubleshooting,
Monitoring, troubleshooting,Monitoring, troubleshooting,
Monitoring, troubleshooting,
 
Programming web application
Programming web applicationProgramming web application
Programming web application
 
User controls
User controlsUser controls
User controls
 
Custom controls
Custom controlsCustom controls
Custom controls
 
Web services
Web servicesWeb services
Web services
 
Working with xml data
Working with xml dataWorking with xml data
Working with xml data
 
Connected data classes
Connected data classesConnected data classes
Connected data classes
 
Introducing asp
Introducing aspIntroducing asp
Introducing asp
 

Recently uploaded

08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 

Recently uploaded (20)

08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 

DataTable, DataSet, and DataView objects in .NET

  • 1.
  • 2. DataTable  DataColumn  DataRow  DataView  DataSet
  • 3. The DataTable object represents tabular data as rows, columns, and constraints.  Use the DataTable object to hold data in memory while performing disconnected data operations.  Can get a DataTable object by connecting to the database and returning table data.
  • 4. Can be explicitly created by instantiating the DataTable class  You then add DataColumn objects to the class to define the type of data to be held.  The DataColumn objects also contain constraints.  Once the DataTable is defined with columns, you can add DataRow objects that contain data for the table.
  • 5. private DataTable GetDataTable() { DataTable employee = new DataTable("Employee"); DataColumn eid = new DataColumn("Eid"); eid.DataType = typeof(string); eid.MaxLength = 10; eid.Unique = true; eid.AllowDBNull = false; eid.Caption = "EID"; employee.Columns.Add(eid); return employee; }
  • 6. DataType  MaxLength  Unique  AllowDBNull  Caption
  • 7. The primary key of a DataTable object consists of one or more columns that define data that represent a unique identity for each row in the data. employee.PrimaryKey = new DataColumn[] {eid};
  • 8. The DataTable object contains a Rows collection, which contains a collection of DataRow objects.  You can insert data into the Rows collection by using  Add method on the Rows collection  Load method on the DataTable object.
  • 9. DataRow newemployee = employee.NewRow(); newemployee["Eid"] = "123456789A"; newemployee["FirstName"] = "Nancy"; newemployee["LastName"] = "Davolio"; newemployee["Salary"] = 10.00m; employee.Rows.Add(newemployee); Or employee.Rows.Add("987654321X", "Andrew", "Ful ler", 15.00m);
  • 10. employee.LoadDataRow( new object[] { "987654321X", "Janet", "Leverling", 20.00m }, LoadOption.OverwriteChanges);  LoadOption enumeration value that has one of the following values:  OverwriteChanges  PreserveChanges  Upsert
  • 11. Detached : DataRow is created but not added to a DataTable.  Added : DataRow is added to a DataTable.  Unchanged : DataRow has not changed since the last call to the AcceptChanges method. The DataRow changes to this state when the AcceptChanges method is called.  Modified : DataRow has been modified since the last time the AcceptChanges method was called.  Deleted : DataRow is deleted using the Delete method of the DataRow.
  • 12.
  • 13. The AcceptChanges method is used to reset the DataRow state to Unchanged.  After data has been loaded from the database, the RowState property of the loaded rows is set to Added.  Calling AcceptChanges on the DataTable resets the RowState of all of the DataRow objects to Unchanged.  If you modify the DataRow objects, their RowState changes to Modified.  After the changes have been successfully sent to the data store by calling the AcceptChanges method the RowState changes to Unchanged.
  • 14. The Delete method on the DataRow is used to set the RowState of the DataRow to Deleted.  There are many scenarios where you need to undelete a DataRow.  The DataRow object doesn’t have an undelete method, but you can use the RejectChanges method to perform an undelete that may satisfy some scenarios.
  • 15. The DataRow object can hold up to three versions, or copies, of the data: Original, Current, and Proposed.  When the DataRow is created, it contains a single copy of the data, which is the Current version.  When the DataRow is placed into edit mode by executing its BeginEdit method, changes to the data are placed in a second version of the data, called the Proposed version.  When the EndEdit method is executed, the Current version becomes the Original version, the Proposed version becomes the Current version, and the Proposed version no longer exists.   After EndEdit has completed its execution, there are two versions of the DataRow data: Original and Current.
  • 16. You often need to create a full copy of a DataTable in your application.  For example, you might want to assign a DataTable object to a GridView control to allow a user to edit the data, but you also might want to provide a cancel button that aborts all changes on the Web page.  A simple way to implement this functionality is to create a copy of your DataTable object and use the copy for editing.  DataTable copy = employee.Copy();
  • 17. You often require a copy of the DataTable schema without the data.  You can accomplish this by invoking the Clone method on the DataTable.  Use this method when an empty copy of the DataTable is required and to which DataRow objects will be added at a later time. DataTable clone = employee.Clone(); clone.ImportRow(employee.Rows[0]);  The ImportRow method on the DataTable object copies a DataRow from a DataTable that has the same schema.
  • 18. The DataView object provides a window into a DataTable that can be sorted and filtered using the Sort, RowFilter, and RowStateFilter properties.  A DataTable can have many DataView objects assigned to it, allowing the data to be viewed in many different ways without requiring the data to be reread from the database.  The DataView object also contains the AllowDelete, AllowEdit, and AllowNew properties to constrain user input as needed.
  • 19. protected void Button7_Click(object sender, EventArgs e) { //get datatable DataTable employee = GetDataTable(); //sort and display DataView view = new DataView(employee); view.Sort = "LastName ASC, FirstName ASC, Salary DESC"; GridView1.DataSource = view; GridView1.DataBind(); } Also RowFilter can be set to a SQL WHERE clause without the word “WHERE.” view.RowFilter = "LastName like 'A%' and Salary > 15";
  • 20. The DataSet is a memory-based relational representation of data and the primary disconnected data object.  The DataSet contains a collection of DataTable and DataRelation objects.
  • 21. private DataSet GetDataSet() { DataSet companyData = new DataSet("CompanyList"); DataTable company = companyData.Tables.Add("company"); company.Columns.Add("Id", typeof(Guid)); company.Columns.Add("CompanyName", typeof(string)); company.PrimaryKey = new DataColumn[] { company.Columns["Id"] }; DataTable employee = companyData.Tables.Add("employee"); employee.Columns.Add("Id", typeof(Guid)); employee.Columns.Add("companyId", typeof(Guid)); employee.Columns.Add("LastName", typeof(string)); employee.Columns.Add("FirstName", typeof(string)); employee.Columns.Add("Salary", typeof(decimal)); employee.PrimaryKey = new DataColumn[] { employee.Columns["Id"] }; companyData.Relations.Add( "Company_Employee", company.Columns["Id"], employee.Columns["CompanyId"]); return companyData;
  • 22. Label lbl = GetLabel(275, 20); DataSet companyList = GetDataSet(); DataRelation dr = companyList.Relations["Company_Employee"]; DataRow companyParent = companyList.Tables["company"].Rows[1]; lbl.Text = companyParent["CompanyName"] + "<br />"; foreach (DataRow employeeChild in companyParent.GetChildRows(dr)) { lbl.Text += "&nbsp;&nbsp;&nbsp;" + employeeChild["Id"] + " " + employeeChild["LastName"] + " " + employeeChild["FirstName"] + " " + string.Format("{0:C}", employeeChild["Salary"]) + "<br />"; } lbl.Text += "<br /><br />"; DataRow employeeParent = companyList.Tables["employee"].Rows[1]; lbl.Text += employeeParent["Id"] + " " + employeeParent["LastName"] + " " + employeeParent["FirstName"] + " " + string.Format("{0:C}", employeeParent["Salary"]) + "<br />"; DataRow companyChild = employeeParent.GetParentRow(dr); lbl.Text += "&nbsp;&nbsp;&nbsp;" + companyChild["CompanyName"] + "<br />";
  • 23. A DataSet can be serialized as XML or as binary data to a stream or file.  The DataSet can also be deserialized from XML or binary data from a stream or file. The serialized data can be transferred across a network via many protocols, including HTTP.