Hi

convert datatable to IEnumerable list in c#


using System;
using System.Linq;
using System.Data;

public partial class GetIenumerablevalues : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnGetValues_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("UserId"typeof(Int32));
dt.Columns.Add("UserName"typeof(string));
dt.Columns.Add("Education"typeof(string));
dt.Rows.Add(1, "Suresh Dasari""B.Tech");
dt.Rows.Add(2, "Rohini Dasari""Msc");
dt.Rows.Add(3, "Madhav Sai""MS");
dt.Rows.Add(4, "Praveen""B.Tech");
dt.Rows.Add(6, "Sateesh""MD");
dt.Rows.Add(7, "Mahesh Dasari""B.Tech");
dt.Rows.Add(8, "Mahendra""CA");
var data = dt.AsEnumerable().Select(row =>
new
{
UserId = row["UserId"].ToString(),
UserName = row["UserName"].ToString(),
Education = row["Education"].ToString()
});
foreach (var row in data)
{
lblval.Text += "UserId: "+row.UserId+", Name: " +row.UserName+", Value: "+row.Education+"<br/>";
}
}
}
Previous
Next Post »

1 comments:

Write comments
Dimaria
AUTHOR
9 October 2017 at 07:19 delete

Special chars is not display correctly

Reply
avatar