connectseekers.com

Sunday, 22 May 2016

How To Add Data In Datatable In C#.Net

5/22/2016 - By Pranav Singh 0


This article will show you how you can add data to a datatable manually using c#.net. In this article I have added column and rows to datatable.
Some of my previous articles are as follows: Transfer DataTable Row Value to List Collection In C#.Net, Browse, Read and Populate or Show or Bind CSV File Data In GridView Using C#.Net in Asp.net, Gridview Auto Generate Row Number In Asp.Net Using C#.Net, How To Read XML File In DataSet And Display in DataGridview Using C#.Net, Get Distinct Value From DataTable Using C#.Net and VB.Net, Read XML File Data Using Linq Query and Add in DataTable to Bind GridView in Asp.net Using C#.Net, Bind & Search XML File Data and Display in GridView in Asp.net Using C#.Net, Bind Asp.net DropdownList Control by XML File Data Using DataSet in C#.Net, Bind Asp.net ListBox Control by XML File Data Using DataSet in C#.Net.

So here is the code to add records in datatable Is as follows:

           
            DataTable dt = new DataTable();
            dt.Clear();
            dt.Columns.Add("CountryName");
            dt.Columns.Add("Population");
            dt.Columns.Add("Code");

            DataRow dataRow1 = dt.NewRow();
            dataRow1["CountryName"] = "India";
            dataRow1["Population"] = "125 Cr";
            dataRow1["Code"] = "IN";
            dt.Rows.Add(dataRow1);

            DataRow dataRow2 = dt.NewRow();
            dataRow2["CountryName"] = "Pakistan";
            dataRow2["Population"] = "50 Cr";
            dataRow2["Code"] = "PK";
            dt.Rows.Add(dataRow2);

            DataRow dataRow3 = dt.NewRow();
            dataRow3["CountryName"] = "United States";
            dataRow3["Population"] = "25 Cr";
            dataRow3["Code"] = "US";
            dt.Rows.Add(dataRow3);

About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com
Email Id : contact@aspdotnet-pools.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Top jQuery Plugins

Global Classified : Connectseekers.com
© 2014
back to top