EDN Admin
Well-known member
Hi,
<br/>
I am working on .NET 4.0 windows application and I use LINQ to read data from CSV file.
Following fields are in the CSV file and are separated by Semi colon.
User can search for a record in the CSV using User id or Name or Email or Country code.
I want to filter the records in the CSV using LINQ. I tried the below code but want to extent this to other columns as well.
<pre class="prettyprint List<string> master = System.IO.File.ReadAllLines(strMasterCSVPath).ToList();
var RowMaster = from row in master
where row.StartsWith(strUserID)
select row;[/code]
<table border="0" cellspacing="0" cols="5" frame="void" rules="none
<colgroup><col width="63 <col width="86 <col width="157 <col width="93 <col width="86 </colgroup>
<tbody>
<tr>
<td align="left" height="17" width="63 User Id</td>
<td align="left" width="86 Name</td>
<td align="left" width="157 Email</td>
<td align="left" width="93 Country code</td>
<td align="left" width="86 DB Row ID</td>
</tr>
<tr>
<td align="left" height="18 100</td>
<td align="left Sam</td>
<td align="left mailto:abc1@test.com abc1@test.com </td>
<td align="left CA</td>
<td align="left 3000</td>
</tr>
<tr>
<td align="left" height="17 101</td>
<td align="left Joe</td>
<td align="left abc2@testemail.com</td>
<td align="left US</td>
<td align="left 3001</td>
</tr>
<tr>
<td align="left" height="18 102</td>
<td align="left Matt</td>
<td align="left mailto:xyz@test.com xyz@test.com </td>
<td align="left FR</td>
<td align="left 3002</td>
</tr>
<tr>
<td align="left" height="18 103</td>
<td align="left John</td>
<td align="left mailto:test@testmail.com test@testmail.com </td>
<td align="left US</td>
<td align="left 3003</td>
</tr>
<tr>
<td align="left" height="18 104</td>
<td align="left Leo</td>
<td align="left mailto:Leo@test.com Leo@test.com </td>
<td align="left US</td>
<td align="left 3004</td>
</tr>
</tbody>
</table>
How to filter the records based on the column value entered by the user?
For example,
If the user enters User Id as 102, I want to fetch the row with the user Id 102.<br/>
If the user enters Country code as CA, I want to fetch all the rows with the country code CA
Thanks<br/>
Ashok
<br/>
View the full article
<br/>
I am working on .NET 4.0 windows application and I use LINQ to read data from CSV file.
Following fields are in the CSV file and are separated by Semi colon.
User can search for a record in the CSV using User id or Name or Email or Country code.
I want to filter the records in the CSV using LINQ. I tried the below code but want to extent this to other columns as well.
<pre class="prettyprint List<string> master = System.IO.File.ReadAllLines(strMasterCSVPath).ToList();
var RowMaster = from row in master
where row.StartsWith(strUserID)
select row;[/code]
<table border="0" cellspacing="0" cols="5" frame="void" rules="none
<colgroup><col width="63 <col width="86 <col width="157 <col width="93 <col width="86 </colgroup>
<tbody>
<tr>
<td align="left" height="17" width="63 User Id</td>
<td align="left" width="86 Name</td>
<td align="left" width="157 Email</td>
<td align="left" width="93 Country code</td>
<td align="left" width="86 DB Row ID</td>
</tr>
<tr>
<td align="left" height="18 100</td>
<td align="left Sam</td>
<td align="left mailto:abc1@test.com abc1@test.com </td>
<td align="left CA</td>
<td align="left 3000</td>
</tr>
<tr>
<td align="left" height="17 101</td>
<td align="left Joe</td>
<td align="left abc2@testemail.com</td>
<td align="left US</td>
<td align="left 3001</td>
</tr>
<tr>
<td align="left" height="18 102</td>
<td align="left Matt</td>
<td align="left mailto:xyz@test.com xyz@test.com </td>
<td align="left FR</td>
<td align="left 3002</td>
</tr>
<tr>
<td align="left" height="18 103</td>
<td align="left John</td>
<td align="left mailto:test@testmail.com test@testmail.com </td>
<td align="left US</td>
<td align="left 3003</td>
</tr>
<tr>
<td align="left" height="18 104</td>
<td align="left Leo</td>
<td align="left mailto:Leo@test.com Leo@test.com </td>
<td align="left US</td>
<td align="left 3004</td>
</tr>
</tbody>
</table>
How to filter the records based on the column value entered by the user?
For example,
If the user enters User Id as 102, I want to fetch the row with the user Id 102.<br/>
If the user enters Country code as CA, I want to fetch all the rows with the country code CA
Thanks<br/>
Ashok
<br/>
View the full article