Google News
logo
ADO.NET - Interview Questions
Explain about DataSet types in ADO.NET.
DataSet can be said as a collection of database tables(row and column format) that holds the data. There are two types of DataSet in ADO.NET. They are :
 
Typed DataSet : A typed DataSet is derived from the DataSet base class and can be created by selecting the DataSet option provided by Visual Studio. It will be created as an XML schema(.xsd file) that contains DataSet structure information such as rows, columns, and tables. Data from the database is moved into a dataset and from the dataset to another component in the XML format.

Untyped DataSet : Untyped DataSet does not have an associated XML schema with it. Users are supposed to add columns, tables, and other elements to it. Properties can be set during design time or can add them during run time.

Example program for the usage of DataSet :
using System;  
using System.Data.SqlClient;  
using System.Data;  
namespace DataSetDemo  
{  
    public partial class DataSetExample : System.Web.UI.Page  
    {  
        protected void Page_Load(object sender, EventArgs e)  
        {  
            using (SqlConnection conn = new SqlConnection("data source=.; database=employee; integrated security=SSPI"))  
            {  
                SqlDataAdapter da = new SqlDataAdapter("Select * from employee", conn);  
                DataSet d = new DataSet();  
                da.Fill(d);  
                GridView1.DataSource = d;  
                GridView1.DataBind();  
            }  
        }  
    }  
}​

 

Here, DataSet will be filled by DataAdapter that receives data from the employee table. This DataSet will be used to display the information received from the employee database.
Advertisement