Thursday, May 29, 2014

Get The Specific Column From The Data Table Using Asp.Net C#

Step 1:- Creating the dynamic data table

DataTable dt = new DataTable();
dt.Columns.Add("UserId", typeof(int));
dt.Columns.Add("UserName", typeof(string));
dt.Columns.Add("Education", typeof(string));
dt.Rows.Add(1, "Lokesh", "B.Tech");
dt.Rows.Add(2, "Vijay", "Msc");
dt.Rows.Add(3, "Balaji", "MS");
dt.Rows.Add(4, "Charan", "B.Tech");
dt.Rows.Add(5, "Durga", "MD");
dt.Rows.Add(6, "Shiva", "B.Tech");
dt.Rows.Add(7, "Venkat", "CA");

Step 2:- By using the DefaultView Key word get the specific column from the existing the data table

DataTable dtDistinct = dt.DefaultView.ToTable(true, "UserName");

It will return only the "UserName” Column details


No comments:

Post a Comment