Saturday, March 23

How to retrieve data using linq query in DataTable

Introduction:-
                     Here I have explained How to retrieve data using linq query stored in DataTable in asp.net.
Description:-
In this Article I will explain how to store data into datatable using linq query in asp.net.I have used here data context class and by creating the object of that class we can get the tables present inside that object.


To store the data into datatable follow the below steps.
 
ShibashishDataClassesDataContext dc = new ShibashishDataClassesDataContext();
 
var x = from n in dc.Table1 select n;
 
IDbCommand cmd = dc.GetCommand(x);
 
SqlDataAdapter adapter = new SqlDataAdapter();
 
adapter.SelectCommand = (SqlCommand)cmd;
 
DataTable dt = new DataTable();
 
cmd.Connection.Open();
 
adapter.FillSchema(dt, SchemaType.Source);
 
adapter.Fill(dt);

Like this you can store your data into datatable.If you want to learn more about linq query then go to this links
http://www.dotnetocean.com/2013/03/how-to-retrieve-data-using-linq-query.html,http://www.dotnetocean.com/2012/07/join-more-than-three-tables-using-linq.html,http://www.dotnetocean.com/2012/05/editing-updating-and-deleting-data-in.html,http://www.dotnetocean.com/2012/05/fetching-data-from-database-and.html,http://www.dotnetocean.com/2012/05/inserting-data-to-database-using-linq_03.html,http://www.dotnetocean.com/2012/05/inserting-data-to-database-using-linq.html

Keep coding...

Thanks Shibashish Mohanty
 

No comments:

Post a Comment

Please don't spam, spam comments is not allowed here.

.

ShibashishMnty
shibashish mohanty