Senior & Expert .Net Developers Discussion Forum by Nyros Technologies

HIRE .Net Expert Developers Programmers Coders From India
Ruby on Rails PHP .Net Developers Community, Nyros Technologies, Kakinada
 
Log in  or IF not a member please REGISTER
Username:
Password:   


Keyword
Log in | Profile 

How to Convert Linq provided data to data table?

 
Post new topic   Reply to topic    Senior & Expert .Net Developers Discussion Forum by Nyros Technologies Index -> ADO.Net
View previous topic :: View next topic  
Author Message
pavani



Joined: 26 Mar 2010
Posts: 37

PostPosted: Wed Jun 23, 2010 12:12 pm    Post subject: How to Convert Linq provided data to data table? Reply with quote

Hi Experts..,

I am using Linq on ADO.net Entity in my project.

I want retrieve the data and store it in data table. I know how to bind the data to data table using Sql. But using linq how it can be done. can any body help me please.
_________________
Pavani....Smile
Back to top
View user's profile Send private message
rajesh



Joined: 26 Mar 2010
Posts: 43

PostPosted: Wed Jun 23, 2010 12:46 pm    Post subject: Reply with quote

Hello Pavani..,


There is no Predefined methods or classes like adapter to convert bind the linq resultant data to data table.

we need implement a method for it.

Here am giving you a sample method to convert Linq to data table.

public DataTable LINQtoDT<T>(IEnumerable<T> vlist)
{
DataTable dataReturn = new DataTable();
PropertyInfo[] Pro = null;
if (vlist == null) return dataReturn;
foreach (R rec in varlist)
{
if (Pro == null)
{
Pro = ((Type)rec.GetType()).GetProperties();
foreach (PropertyInfo pinfo in Pro)
{
Type colType = pinfo.PropertyType;
if ((colType.IsGenericType) && (colType.GetGenericTypeDefinition()
== typeof(Nullable<>)))
{
colType = colType.GetGenericArguments()[0];
}
dataReturn.Columns.Add(new DataColumn(pinfo.Name, colType));
}
}

DataRow dr = dataReturn.NewRow();
foreach (PropertyInfo pinfo in Pro)
{
dr[pinfo.Name] = pinfo.GetValue(rec, null) == null ? DBNull.Value : pinfo.GetValue
(rec, null);
}
dataReturn.Rows.Add(dr);
}
return dataReturn;
}
_________________
Cool***************Cool

Best Regards
Rajesh Mani.
Nyros Technologies.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Senior & Expert .Net Developers Discussion Forum by Nyros Technologies Index -> ADO.Net
Page 1 of 1


 latest topics 
 Topics   Replies   Author   Views   Last Post 
No new posts How to Add Update Delete for gridview using Webservice
1 sanjay 31 Fri Sep 10, 2010 7:05 am
setty View latest post
No new posts Is there any free webhosts that support ASP.NET. ?
2 Balaji 634 Tue Sep 07, 2010 10:24 am
chrisadam View latest post
No new posts Hostings For ASP.NET 2.0 with SQL Server
2 Avash 676 Tue Sep 07, 2010 10:21 am
chrisadam View latest post
No new posts Exceptional Manger
1 suraj 51 Thu Sep 02, 2010 8:52 am
Rahul View latest post
No new posts background image for UITableView
0 kumar 55 Wed Sep 01, 2010 10:34 am
kumar View latest post
No new posts Types of Run time exceptions
1 Dheeraj 52 Wed Sep 01, 2010 8:58 am
venkat View latest post
No new posts Access Web Page content in Windows Forms without WebBrowser
3 mouli 273 Wed Sep 01, 2010 7:31 am
rajesh View latest post
No new posts Explain Interlocked Class & Daemon Thread's?
1 mukundh 76 Wed Sep 01, 2010 7:19 am
setty View latest post
No new posts Life Cycle Of Delegate
0 vinay 40 Wed Sep 01, 2010 7:14 am
vinay View latest post
No new posts Accessing methods defined in another page
1 suraj 37 Tue Aug 31, 2010 12:45 pm
Rahul View latest post




Hire an expert .Net developer / coder / programmer or development team from India now!!

Other Forums : Ruby on Rails   ::   PHP   |   Free unlimited HTML CSS templates download

Nyros Technologies   |   Kakinada City Portal   |   Developers Blog   |   About .Net Experts   |   More