• How to add DataTable to DataSet in C#

    by  • June 20, 2013 • Microsoft .NET C# (C-Sharp), Microsoft ASP.NET • 0 Comments

    What is DataSet?

    A DataSet is an in-memory representation of data. It represents cache of data retrieved from database. DataSet is a disconnected architecture that means we only need connection with database for small amount of time to fill DataSet and close connection. Now we can manipulate data from DataSet without any connection to database. DataSet is actually a collection of one or more DataTables. So we can say that we use DataSet to store one or many DataTables in it.

    What is DataTable?

    A DataTable is also an in-memory representation of data and it also represents cache of data retrieved from database. It stores data in tabular format so it contains rows, columns and cells. If we have data in one table then we can use DataTable in ASP.NET. It is also a disconnected architecture so we can fill DataTable and manipulate data from DataTable without any connection to database.

    Add DataTable to DataSet

    How we can create a DataTable in ASP.NET is explained here. We can add multiple DataTables to a DataSet. DataSet behaves like a container for DataTable. Let me show you how we can add a DataTable to DateSet in C#

    As per your requirements you can create DataTable in C# or you can fetch data from database and store in DataTable and then you can add DataTable to DataSet.

    You need to have following namespaces in your code file.

    Create DataTable and fill data

    Create DataSet and add DataTable to DataSet

    Fetch data from database and fill DataTable

    Create DataSet and add DataTable to DataSet

    You can also create DataSet with name and can change its name later

    Best WordPress Themes and Plugins with Great Team and Support!

    Avatar of GetCodeSnippet.com


    GetCodeSnippet.com provides you high quality Microsoft .NET development related articles, tutorials and sample code for ASP.NET, C#, VB.NET, AJAX, WCF, WPF, Web Services, Windows Services, SQL Server and other technologies.

    Leave a Reply