score:3
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;
}
Source: stackoverflow.com
Related Articles
- 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?
- Can't add a new record with an integer value into database by using linq from code C#
- 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?
- Querying the database using EF Code First and Linq
- How to upload a document to Sql server database using linq to sql?
- Convert string[] to int[] in one line of code using LINQ
- Query Microsoft Access MDB Database using LINQ and C#
- Read Excel using LINQ
- Get X random elements from table in database using Linq or lambda in C#
- Error connecting to database using Linq
- Some data is missing in the Export to Excel using DataTable and Linq
- Retrieving Data from database within the last 7 days using linq
- Left outer join using LINQ -- understanding the code
- How to reuse a linq expression for 'Where' when using multiple source tables
- Avoiding code repetition when using LINQ
- Using LINQ to delete an element from a ObservableCollection Source
- Using LINQ find nearby places from database
- LINQ Source Code Available
- Check if a table exists within a database using LINQ
- Trying to get a list of files in a directory by created date using LINQ
- Start reading data from a specific row of excel using Linq in C#
- how delete more than one record from database using Linq in asp.net mvc
- Delete all records from a database using LINQ to SQL
- Efficiently check if record exists in database using Entity framework LINQ
- How can I write the following code more elegantly using LINQ query syntax?
- How can I code an outer join using LINQ and EF6?
- Using LINQ with Action to delete old files
- Using LINQ to SQL to search entire database
- C# .Net 3.5 Code to replace a file extension using LINQ
- Converting a List of String Type To Decimal Type List
- Select and Print list of PDF files from a folder
- c# Linq select distinct date time days
- Entity Framework Code First - The entity or complex type cannot be constructed in a LINQ to Entities query
- C# - Intersection of Dictionary<int, SortedList<int, List<int>>>
- Combine multiple Linq Where statements
- How to compare 2 comma seperated string values and update in existing list at same position?
- How can I optimize this linq query?
- How can I get 10 entries from a database, ordered by score, given a starting position, using Entity Framework?
- linq to sql string property contains queryparam array
- Linq Query with join on subquery
- Use List<Tuple<int, int>> to return data in Linq
- Return List from Query
- What is d__92 in exception message?
- Adding In and NotIn to System.Linq.Expressions.Expression, is it possible?
- ObjectQuery.select() method for linq to entities returns error
- How to build a LINQ expression with Contains method from IEnumerable?
- How can I pull the checked items from CheckBoxList in a repeater?
- Generically Flatten XDocument using Linq?
- Is there some way of "peeking" a MoveNext(), or how can I get past this fencepost issue?