score:0
static datatable getdatatablefromcsv(string path, bool isfirstrowheader)
{
datatable datatable = null;
using (var instream = new filestream(path, filemode.open, fileaccess.read, fileshare.readwrite))
using (var sr = new streamreader(instream))
{
string line;
while ((line = sr.readline()) != null)
{
var fields = line.split(',');
if (datatable == null) // create datatable based on header row
{
datatable = new datatable();
foreach (var field in fields)
datatable.columns.add(new datacolumn(field));
continue; // don't add header row to rows collection
}
datatable.rows.add(fields);
}
}
return datatable;
}
Source: stackoverflow.com
Related Query
- Efficient Way to SQL Csv w/ > 255 Columns in C#?
- Most efficient way to update with LINQ to SQL
- What's the most efficient way to get only the final row of a SQL table using EF4?
- Efficient way to split CSV files in c#
- Most efficient way to check to see if there is any data in a SQL row
- One way syncing of 4 columns in SQL Server
- Efficient Way for Finding Reference Object in LINQ to SQL
- Why is .Contains slow? Most efficient way to get multiple entities by primary key?
- Best way for retrieving single record results in LINQ to SQL
- What is the easiest way to find the LINQ statement for a SQL statement
- linq to sql join on multiple columns using lambda
- Odd behavior in LINQ to SQL with anonymous objects and constant columns
- Most Efficient way to test large number of strings against a large List<string>
- Why didn't the LINQ designers stick with using the way sql is written today?
- EF Core queries all columns in SQL when mapping to object in Select
- Entity Framework dbset most efficient way of deleting
- Efficient way to determine collection has at least 2 items
- Linq To SQL Select Dynamic Columns
- Efficient way to call .Sum() on multiple properties
- What is the most efficient way to obtain an ordered range using EntityFramework?
- Best way of constructing dynamic sql queries in C#/.NET3.5?
- LINQ to SQL - best way to switch between test & dev db
- linq to sql startwith performance indexed columns
- Linq to SQL select multiple columns
- Good way to time SQL queries when using Linq to SQL
- Best way to read csv file in C# to improve time efficiency
- LINQ to SQL Select Distinct by Multiple Columns and return entire entity
- What's the most efficient way to convert a DataTable to an object[,]?
- What is the fastest/most efficient way to read this XML to Dictionary (Linq or something else?)
- Best way to update in Linq To SQL
More Query from same tag
- Apply SelectMany to three or more sequences
- Left Outer Join two data tables - VB.NET
- How do I perform a SelectMany in C# query syntax using a many-to-many joining table?
- MVC 5 Cannot implicitly convert type 'System.Linq.IQueryable to bool?
- Linq GroupBy into new object
- LINQ Query Return unique list of lists
- Querying a list in a list efficently
- Is is possible to add .Where() on a child collection property using nhibernate linq?
- How flatten a list with many arrays inside using LINQ
- Linq Projection Count By Id
- How can I structure nHibernate QueryOver where (X AND Y) OR (null AND null)
- How to use .Where in generic list
- LINQ: Searching a collection within a collection for a single object
- sort only particular rows sql server
- Cannot convert method group 'SingleOrDefault' to non-delegate type 'Product'. Did you intend to invoke the method?
- Sum and order nested List<double>
- Unable to cast object of type 'System.Double' to type 'System.String' linq query
- Using Linq to group hourly and get an hourly average
- How to get sum of data in a list using multiple column values
- OrderBy date format with null values
- Understanding ClientContext.Load's Parameters
- Split number from string for order by clause in Entity Framework
- Simple LINQ to XML
- using equal and not equal in a linq join
- Get the inner points which are on a straight line
- List.OrderByDescending Linq not working
- StreamInsight query based on holding period
- Issue with adding Linq Where clause containing a string Contains test
- Date Difference Logic in LINQ
- How to get average value using LEFT JOIN in LINQ and Lambda