Click here to Skip to main content
14,735,777 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I am beginner of LINQ,My requirement is text box value to compare with data table column values.If the text box value contain the data table then return only those records.
i was try to create some LINQ query.but it's not working any one could you please help to me for this requirement.

What I have tried:

I was tried the below LINQ query.
DT=DT.AsEnumerable().Where(x=>x.Field<string>("ImportTargetEntity")==Textboxvalue)
Posted
Updated 2-Jun-20 23:35pm
v2
Comments
Maciej Los 3-Jun-20 3:46am
   
Please, define "but it's not working".
Richard MacCutchan 3-Jun-20 3:59am
   
Have you actually run this code in the debugger to see what values are being tested?

1 solution

Seems, you want to filter data of one DataTable into another (or even the same) DataTable.

If you would like to load filtered data into the same DataTable:
DT=DT.AsEnumerable()
    .Where(x=>x.Field<string>("ImportTargetEntity")==Textboxvalue)
    .CopyToDataTable();
DataGridView1.DataSource = DT;


If you would like to load data into another datatable:
DataTable AnotherDT = DT.Clone();
AnotherDT = DT.AsEnumerable()
    .Where(x=>x.Field<string>("ImportTargetEntity")==Textboxvalue)
    .CopyToDataTable();
DataGridView2.DataSource = AnotherDT;
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900