Interview Question: Difference between DataTable and dataset in asp.net - Free Asp.Net,MVC,AngularJs,Jquery,Javascript,Sql Server,WCF,Entity framework snippets and tutorial

Interview Question: Difference between DataTable and dataset in asp.net

In this article I am going to explain the differences between DataTable and dataset in asp.net.


DataTable :
     1.    A DataTable is an in-memory representation of a single database table. It represents a single table and has rows and columns.
     2.      DataTable is less flexible.
     3.      DataTable is lighter because it contains the data of single table only.
     4.      DataTable fetches only one TableRow at a time.
     5.      DataTable , DataSource can’t be serialized.
     6.      There is no DataRelation object in DataTable .
     7.      There is no Unique Constraint and Foreign Key Constraint object available in DataTable.
Example of DataTable:
SqlDataAdapter adp = new SqlDataAdapter("Select * from Tb_Student", con);
        //DataTable  object
        DataTable  dt = new DataTable ();      
        adp.Fill(dt);
        //check the DataTable  contains data or not
        if (dt.Rows.Count > 0)
        {
            grdstudent.DataSource = dt;
            grdstudent.DataBind();
        }


DataSet:
     1.      DataSet is the disconnected architecture. DataSet is an in-memory representation of a database-like structure which has the collection of datables and has multiple rows and columns.
     2.      DataSet is more flexible.
     3.      DataSet is heavy object because it can contain data of multiple tables.
     4.      DataSet can fetch multiple TableRows at a time.
     5.      DataSet is serialized DataSource.
     6.      In DataSet, DataTable objects can be related to each other with DataRelation objects.
     7.      In DataSet, data integrity is enforced by using the Unique Constraint and Foreign Key Constraint objects.
Example of DataSet:
SqlDataAdapter adp = new SqlDataAdapter("Select * from Tb_Student", con);
        //DataSetobject
        DataSetds = new DataSet();      
        adp.Fill(ds);
        //check DataSettables contains data or not
        if (ds.Tables[0].Rows.Count >0)
        {
            grdstudent.DataSource = ds;
            grdstudent.DataBind();
        }

    In this article i have explained mostly asked interview question difference between DataTable and Dataset in asp.net. I hope you enjoyed this article. 

What do you think about this article?

If you found this article useful, please share and follow on Facebook, Twitter, Google Plus and other social media websites. To get free updates subscribe to newsletter. Please put your thoughts and feedback in comments section.

Share this

Share on FacebookTweet on TwitterPlus on Google+


EmoticonEmoticon