score:0
2 easy ways without using linq:
using system.io;
using system.data;
using system.data.oledb;
public datarow[] getusers(string path, string id)
{
datatable dt = new datatable();
if (file.exists(path))
{
using (oledbconnection con = new oledbconnection(string.format("provider=microsoft.jet.oledb.4.0;data source={0};extended properties=excel 8.0", path)))
{
oledbdataadapter da = new oledbdataadapter(string.format("select * from users", id), con);
da.fill(dt);
}
}
string expression = string.format("{0} = '{1}' and {2} <> ''", id, "first_name", "last_name");
string sort = "last_name asc";
return dt.select(expression, sort);
}
public datatable getusers(string path, string id)
{
datatable dt = new datatable();
if (file.exists(path))
{
using (oledbconnection con = new oledbconnection(string.format("provider=microsoft.jet.oledb.4.0;data source={0};extended properties=excel 8.0", path)))
{
string expression = string.format("{0} = '{1}' and {2} <> ''", id, "first_name", "last_name");
oledbdataadapter da = new oledbdataadapter(expression, con);
da.fill(dt);
}
}
return dt;
}
score:3
Source: stackoverflow.com
Related Query
- How to upload excel files to database using linq?
- How can I check the number of calls to the database in LINQ query when using .NET Core and Code First?
- how to fetch data from database using linq query for relationship 1:N and N:N (between 3 entity) in asp.net mvc EF code first?
- How to upload a document to Sql server database using linq to sql?
- How to reuse a linq expression for 'Where' when using multiple source tables
- how delete more than one record from database using Linq in asp.net mvc
- How can I write the following code more elegantly using LINQ query syntax?
- How can I code an outer join using LINQ and EF6?
- how to convert Database Hierarchical Data to XML using ASP.net 3.5 and LINQ
- How to flatten a multi level XML into a single level XML using c# code LINQ
- How to write this code using the Linq Extension Method-Syntax?
- Can't add a new record with an integer value into database by using linq from code C#
- How to update a table in database using LINQ in F#?
- LINQ - database query using "into", how do I reference data prior to "into" in the select clause?
- I have loaded Excel files into .NET using LINQ, now how to bulk insert data into DB (oracle) tables?
- How to dynamically query the database using LINQ and a variable?
- How do I select the top ten scores in a database table full of scores using linq in C#
- How do I select multiple items from a database using LINQ
- How to get latest id only from database using LINQ in ASP.NET Core Web API?
- How to simplify the code Using LINQ
- Using only Linq or Lambda, how do I combine both pieces of code to return List<Entity> e?
- How to handle nulls in this LINQ Code using a possible null List?
- How to show 2nd row on Data in Next Button Click in C# and XML database using LINQ
- Using LINQ and EF, how to remove values from database where not in list of items
- How to delete a single row from database using linq query?
- How to import data to GridView Using Linq To Excel
- How to update my model code using LINQ
- How to update the data in database using linq
- How to match exact Id within Comma seperated database column using LINQ and Lambda
- How to add Timestamp value in SQL database by using LINQ
More Query from same tag
- Get a count of a linked collection using OData and LINQ
- Cannot implicitly convert type System.Collections.Generic.List<IEnumerable> to <IEnumerable
- linq groupby and max count
- How to group on list of name with first letter?
- LINQ to SQL: select array of arrays of integers in one query
- Return min value in group with lambda/linq query
- How to create record on cascade tables with linq in mvc
- Populate StackPanel with checkbox's from Database
- Strategies for suppring calculated Types in LINQ to Entities
- how to yield an anonymous class in IEnumerable.GroupBy<T> "on the fly" (without enumerating result) in C# LINQ?
- Convert lambda expression to expression tree
- How to go through 2 vectors in paralle using the same linq statement
- Linq Distinct not bringing back the correct results
- What does a GroupBy KeySelector function look like?
- Error when using WCF dataservice
- Need "Method return type" of data selected with LINQ from DataTable
- "Where" in nullable property of right join Linq C# lambda expression EF Core
- Why does sp_executesql run slower when parameters are passed as arguments
- How to search for "Not Contains" condition on collection of objects in RavenDB
- Linq cannot select Expression<Action>?
- Linq to Sql: Optimizing lamba expression - clean code
- Performing 1-to-1 Left Outer Join in LINQ using Lambda expression
- How to get xml node value by using xelement in c#
- Asp.net MVC error : LINQ to Entities does not recognize
- Reference-Type Parameters and Linq
- How can I Select an IEnumerable over 2 Tables using LINQ
- Linq Grouping with a sum
- How to extract data from XML
- Run an IQueryable with Entity Framework
- Error while deleting a record with LINQ