Archive for August, 2009

C# code to return a dataset from CSV File (No header)

    public DataSet ParseCSVFile(string filepath, string filename)

    {

        DataSet ds = new DataSet();

        string conn_csv_str;

       conn_csv_str = “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=” + filepath + “;Extended Properties=’text;HDR=NO;FMT=Delimited'”;

 

        string sql_select;

 

        OleDbConnection obj_oledb_con;

        OleDbDataAdapter  obj_oledb_da;

 

        obj_oledb_con = new OleDbConnection(conn_csv_str);

        obj_oledb_con.Open();

 

        sql_select = “select * from [” + filename + “]”;

 

        obj_oledb_da = new OleDbDataAdapter(sql_select, obj_oledb_con);

        obj_oledb_da.Fill(ds);

        obj_oledb_con.Close();

 

        return ds;

 

    }

, , , , , ,

Leave a comment