C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
ADO.NET DataSetIt is a collection of data tables that contain the data. It is used to fetch data without interacting with a Data Source that's why, it also known as disconnected data access method. It is an in-memory data store that can hold more than one table at the same time. We can use DataRelation object to relate these tables. The DataSet can also be used to read and write data as XML document. ADO.NET provides a DataSet class that can be used to create DataSet object. It contains constructors and methods to perform data related operations. DataSet Class Signaturepublic class DataSet : System.ComponentModel.MarshalByValueComponent, System.ComponentModel.IListSource, System.ComponentModel.ISupportInitializeNotification, System.Runtime.Serialization.ISerializable, System.Xml.Serialization.IXmlSerializable DataSet Constructors
DataSet Properties
DataSet MethodsThe following table contains some commonly used methods of DataSet.
Example:Here, in this example, we are implementing DataSet and displaying data into a gridview. Create a web form and drag a gridview from the toolbox to the form. We can find it inside the data category. // DataSetDemo.aspx <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DataSetDemo.aspx.cs" Inherits="DataSetExample.DataSetDemo" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> </div> <asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None"> <AlternatingRowStyle BackColor="White" /> <EditRowStyle BackColor="#2461BF" /> <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" /> <RowStyle BackColor="#EFF3FB" /> <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" /> <SortedAscendingCellStyle BackColor="#F5F7FB" /> <SortedAscendingHeaderStyle BackColor="#6D95E1" /> <SortedDescendingCellStyle BackColor="#E9EBEF" /> <SortedDescendingHeaderStyle BackColor="#4870BE" /> </asp:GridView> </form> </body> </html> CodeBehind // DataSetDemo.aspx.csusing System; using System.Data.SqlClient; using System.Data; namespace DataSetExample { public partial class DataSetDemo : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { using (SqlConnection con = new SqlConnection("data source=.; database=student; integrated security=SSPI")) { SqlDataAdapter sde = new SqlDataAdapter("Select * from student", con); DataSet ds = new DataSet(); sde.Fill(ds); GridView1.DataSource = ds; GridView1.DataBind(); } } } } Output: Execute this code by the combination of Ctrl+F5. It will produce the following output.
Next TopicADO.NET DataAdapter
|