Introduction: 
Here I will explain how to convert datatable to IEnumerable list in c#, vb.net using as.npet. IEnumerable list is a base for all collections and its having ability to loop through the collection by using current property, MoveNext and Reset methods in c#, vb.net.
Description:
   
In previous articles I explained convert datatable to json string in c#, convert datatable to generic list using LINQ, convert datatable to xml string in asp.net, convert datatable or dataset to array in asp.net and many articles relating to asp.net, c#, vb.net, jQuery and JavaScript and. Now I will explain how to convert datatable to IEnumerable list in c#, vb.net using as.npet.
In previous articles I explained convert datatable to json string in c#, convert datatable to generic list using LINQ, convert datatable to xml string in asp.net, convert datatable or dataset to array in asp.net and many articles relating to asp.net, c#, vb.net, jQuery and JavaScript and. Now I will explain how to convert datatable to IEnumerable list in c#, vb.net using as.npet.
C#
Code
| 
 | 
VB.NET
Code
| 
Dim data =
  dt.AsEnumerable().[Select](Function(row) New With { _ 
Key .UserId = row("UserId").ToString(), _ 
Key .UserName = row("UserName").ToString(), _ 
Key .Education = row("Education").ToString() _ 
}) | 
If you want to see it in complete example open your
Default.aspx page and write the code like as shown below
| 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
<title>How to Get IEnumerable
  values in asp.net using c#</title> 
</head> 
<body> 
<form id="form1"
  runat="server"> 
<div> 
<asp:Button ID="btnGetValues"
  Text="Get
  Values" runat="server" 
onclick="btnGetValues_Click" /><br
  /> 
<asp:Label ID="lblval"
  runat="server"></asp:Label> 
</div> 
</form> 
</body> 
</html> | 
Now open your code behind file and write the code
like as shown below 
C#
Code
| 
 | 
VB.NET
Code
| 
 | 
Demo
| If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. | |||
|  Subscribe by RSS  Subscribe by Email | |||

 
2 comments :
nice job suresh..
well defined example.
Note: Only a member of this blog may post a comment.