What's the best way to read CSV data?
I am using C # and am trying to read CSV using this connection string;
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\rajesh.yadava\Desktop\orcad;Extended Properties="Text;HDR=YES;IMEX=1;FMT=Delimited"
This works for tab-delimited data.
I need a connection string that needs to be tab-separated, as well as a comma (,) and pipe (|).
How to create a generic connection string for CSV.
Thanks Rajesh
I know this doesn't answer your questions, but here's a word of warning.
I had to create my own reader as you won't get the correct drivers if you ever run a 64 bit system.
If your software will ever run on a 64-bit system, make sure you test it first and that the oledb or odbc drivers will be present.
source to share
If you need fast sequential access to a CSV file, Fast CSV Reader might be an option. I used it on a project a while ago with great success. It is supposed to be optimized well enough and also provide a cached version if you need it. In addition, it has been updated several times since its first release in 2005 (last updated 2008-10-09) and supports basic data binding through implementation System.Data.IDataReader
.
source to share
Uses the TextFieldParser class?
http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.fileio.textfieldparser.aspx
class CSVFile extends SplFileObject
{
private $keys;
public function __construct($file)
{
parent::__construct($file);
$this->setFlags(SplFileObject::READ_CSV);
}
public function rewind()
{
parent::rewind();
$this->keys = parent::current();
parent::next();
}
public function current()
{
return array_combine($this->keys, parent::current());
}
public function getKeys()
{
return $this->keys;
}
}
then use with:
$csv = new CSVFile('exmaple.csv');
and you can iterate over the lines using:
foreach ($csv as $line)
{
source to share