How to convert a comma seperated file (.csv) into a dataset (C#)

by Manuel 12/13/2007 9:35:00 AM
public DataSet GetCSVFile( string fileName)
{
     string pathName = System.IO. Path .GetDirectoryName(fileName);
     string file = System.IO. Path .GetFileName(fileName);
     OleDbConnection excelConnection = new OleDbConnection
     (@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+ pathName + ";Extended Properties=Text;");
     OleDbCommandexcelCommand = newOleDbCommand(@"SELECT * FROM "+ file, excelConnection);
     OleDbDataAdapterexcelAdapter = newOleDbDataAdapter(excelCommand);
     excelConnection.Open();
     DataSetds = newDataSet();
     excelAdapter.Fill(ds);
     excelConnection.Close();
     return ds;
}

Currently rated 5.0 by 3 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

C# | ASP.NET

Powered by BlogEngine.NET 1.2.0.0
Theme by Mads Kristensen

About the author

Name of author Author name
Something about me and what I do.

E-mail me Send mail

Calendar

<<  September 2010  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

View posts in large calendar

Recent comments

Authors

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010

Sign in