You can fill DataTable from another DataTable using LINQ after doing LINQ operation.
This would be useful in condition like you need to perform some operation on DataTable using LINQ and get back result into another 'DataTable'. Means, you can filter and projection on one DataTable and get result in another DataTable.
We can achieve this by using 'CopyToDataTable' method of LINQ query result variable.
Here is example for this.
In this example we are taking one DataTable which contains product information like ID, name, etc. Now we get only those products which ID is greater than one by LINQ operation on this table and get result in another table using 'CopyToDataTable' method of LINQ query result variable.
C#. Net Example :
VB.Net Examples :
Output :
Below are the books that you would like :
This would be useful in condition like you need to perform some operation on DataTable using LINQ and get back result into another 'DataTable'. Means, you can filter and projection on one DataTable and get result in another DataTable.
We can achieve this by using 'CopyToDataTable' method of LINQ query result variable.
Here is example for this.
In this example we are taking one DataTable which contains product information like ID, name, etc. Now we get only those products which ID is greater than one by LINQ operation on this table and get result in another table using 'CopyToDataTable' method of LINQ query result variable.
C#. Net Example :
private DataTable GetProducts() { DataTable dt = new DataTable(); DataColumn dc; DataRow dr; dt.TableName = "product"; dc = new DataColumn("product_id", int.MaxValue.GetType()); dt.Columns.Add(dc); dc = new DataColumn("product_name"); dt.Columns.Add(dc); dr = dt.NewRow(); dr["product_id"] = 1; dr["product_name"] = "Monitor"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["product_id"] = 2; dr["product_name"] = "Mouse"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["product_id"] = 3; dr["product_name"] = "KeyBoard"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["product_id"] = 4; dr["product_name"] = "LCD"; dt.Rows.Add(dr); return dt; } protected void Page_Load(object sender, EventArgs e) { DataTable dtProd = GetProducts(); var obj = (from m in dtProd.AsEnumerable() where m.Field<int>("product_id") > 1 select m); DataTable dt = obj.CopyToDataTable(); Response.Write("a"); }
VB.Net Examples :
Private Function GetProducts() As DataTable Dim dt As New DataTable() Dim dc As DataColumn Dim dr As DataRow dt.TableName = "product" dc = New DataColumn("product_id", Integer.MaxValue.[GetType]()) dt.Columns.Add(dc) dc = New DataColumn("product_name") dt.Columns.Add(dc) dr = dt.NewRow() dr("product_id") = 1 dr("product_name") = "Monitor" dt.Rows.Add(dr) dr = dt.NewRow() dr("product_id") = 2 dr("product_name") = "Mouse" dt.Rows.Add(dr) dr = dt.NewRow() dr("product_id") = 3 dr("product_name") = "KeyBoard" dt.Rows.Add(dr) dr = dt.NewRow() dr("product_id") = 4 dr("product_name") = "LCD" dt.Rows.Add(dr) Return dt End Function Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim dtProd As DataTable = GetProducts() Dim obj = (From m In dtProd.AsEnumerable() Where m.Field(Of Integer)("product_id") > 1 Select m) Dim dtResult As DataTable = obj.CopyToDataTable() End Sub
Output :
Below are the books that you would like :
Thank you for posting this information
ReplyDeleteDOT NET Training Institute in Chennai | DOT NET Training in Chennai
GREAT INFORMATION..
ReplyDeleteOracle Internship
R Programming Internship
CCNA Internship
Networking Internship
Artificial Intelligence Internship
Machine Learning Internship
Blockchain Internship
Sql Server Internship
Iot Internship
Data Science Internship
ReplyDeleteGeteventlisteners javascript
Karl fischer titration interview questions
How to hack tp link router
T system aptitude questions
Resume for bca final year student
Test case for railway reservation system
T systems pune placement papers
Infrrd bangalore interview questions
Max number in javascript
Paypal integration in php step by step pdf
great....
ReplyDeleteFREE Internship in Nagpur For Computer Engineering Students
Internship For MCA Students
Final Year Projects For Information Technology
Web Design Class
Mechanical Engineering Internship Certificate
Inplant Training For Mechanical Engineering Students
Inplant Training Certificate
Ethical Hacking Course in Chennai
Winter Internship For ECE Students
Internships For ECE Students in Bangalore
very informative
ReplyDeleteHow To Hack On Crosh
Request Letter For Air Ticket Booking To HR
Zeus Learning Aptitude Paper For Software Developer
Cimpress Interview Questions
VCB Rating
Appreciation Letter To Vendor
JS MAX Safe Integer
Why Do You Consider Yourself Suitable For The Position
How To Hack Android Phone From PC
About Bangalore Traffic Essay
GOOD
ReplyDeletehacking course
internship for it students
civil engineering internship report pdf india
ccna course chennai
internship report for civil engineering students in india
internships in hyderabad for cse students 2018
kashi infotech
cse internships in hyderabad
inplant training for diploma students
internship in hyderabad for cse students
GOOD
ReplyDeletenodejs while loop
icici bank po interview questions and answers pdf
craterzone aptitude test
zensoft recruitment process
java developer resume 1 years experience
python developer resume pdf
infrrd private limited interview questions
js int max value
delete * from table oracle
t systems pune aptitude questions
nice think
ReplyDeleteInternship For Aerospace Engineering
Mechanical Engineering Internships in Chennai
Robotics Courses
Kaashiv
Training Letter Format For Mechanical Engineer
Internship For BCA Student
Fake Internship Certificate
MBA Internship
Free Internship For CSE Students in Chennai
Oracle Internship 2020
good
ReplyDeleteResume Format For Bca Freshers
British Airways Interview Questions And Answers Pdf
Asus Tf101 Android 8
Crome://Flags/
T Systems Aptitude Test
Python Resume Ror 2 Years Experience
Ajax Redirect To Another Page With Post Data
Paramatrix Technologies Aptitude Questions And Answers
Adder Subtractor Comparator Using Ic 741 Op-Amp Theory
How To Hack Wifi With Ubuntu
Infycle Technologies, the best software training institute in Chennai offers the leading Python course in Chennai for tech professionals, freshers, and students at the best offers. In addition to the Python course, other in-demand courses such as Data Science, Cyber Security, Selenium, Oracle, Java, Power BI, Digital Marketing also will be trained with 100% practical classes. After the completion of training, the trainees will be sent for placement interviews in the top MNC's. Call 7504633633 to get more info and a free demo.
ReplyDelete